C++ inheritance and name hiding [duplicate]

That is the way the language is designed – names in inner scopes hide names in outer scopes. Here the derived class acts as an inner scope and the base class as an outer scope.

The fact that the functions would be considered overloads if they were in the same scope, doesn’t matter. The hiding works on the names, not on individual functions.

You can override the default, by explicitly adding the name to the derived class:

class Derived : public Base {
    using Base::methodA;   // Now it is visible!

    void methodA(int i) { cout << "Derived.methodA(int i)" << endl ;}

Leave a Comment