Here is an extract of C++ FAQ (section inherited constructors),
People sometimes are confused about the fact that ordinary scope rules
apply to class members. In particular, a member of a base class is not
in the same scope as a member of a derived class:
struct B {
void f(double);
};
struct D : B {
void f(int);
};
B b; b.f(4.5); // fine
D d; d.f(4.5); // surprise: calls f(int) with argument 4
As explained just after in the extract of the FAQ, you need to add using B::f
in D
to overload f
correctly.
In fact, yes I’m confused : since method in struct are public
by default, it is public
in derived struct
also (D
share his methods with B
). So, why does it not work the same as a normal overloaded function ?