Redeclaring members from a base class to avoid name hiding

suggest change

If a using-declaration occurs at class scope, it is only allowed to redeclare a member of a base class. For example, using std::cout is not allowed at class scope.

Often, the name redeclared is one that would otherwise be hidden. For example, in the below code, d1.foo only refers to Derived1::foo(const char*) and a compilation error will occur. The function Base::foo(int) is hidden not considered at all. However, d2.foo(42) is fine because the using-declaration brings Base::foo(int) into the set of entities named foo in Derived2. Name lookup then finds both foos and overload resolution selects Base::foo.

struct Base {
    void foo(int);
};
struct Derived1 : Base {
    void foo(const char*);
};
struct Derived2 : Base {
    using Base::foo;
    void foo(const char*);
};
int main() {
    Derived1 d1;
    d1.foo(42);  // error
    Derived2 d2;
    d2.foo(42);  // OK
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Using declaration:
* Redeclaring members from a base class to avoid name hiding

Table Of Contents
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
129 Using declaration
134 Semaphore
136 Debugging
139 Mutexes
142 decltype