class Base
{
public:
virtual ~Base() {}
virtual void someFunction() const;
virtual void someFunction(int x) const;
};
void Base::someFunction() const {}
void Base::someFunction(int x) const {}
class Derived : public Base
{
public:
void someFunction() const;
};
void Derived::someFunction() const {}
int main(int argc, char **argv)
{
Derived d;
d.someFunction(123);
return 0;
}This, in fact, will not compile and gcc reports the following error:error: no matching function for call to 'Derived::someFunction(int)'While if we remove Derived::someFunction(), the code compiles without errors. First of all, note that there are two orthogonal language features involved here: function overloading and inheritance (overloading vs. overriding).
The scope of Derived becomes nested within the scope of its base class, however, introducing a name in the derived class obscures all overloaded versions of the same function in the Base class, hence the compiler error. This is actually standard behavior, for reasons which will be discussed below.
