A using declaration in a definition of a class A allows you to introduce a name of a data member or member function from a base class of A into the scope of A.
You would need a using declaration in a class definition if you want to create a set of overload a member functions from base and derived classes, or you want to change the access of a class member.
struct Z {
int g();
};
struct A {
void f();
enum E { e };
union { int u; };
};
struct B : A {
using A::f;
using A::e;
using A::u;
// using Z::g;
};
The compiler would not allow the using declaration using
Z::g because Z is not a base class of A.struct A {
template<class T> void f(T);
};
struct B : A {
using A::f<int>;
};
struct A {
private:
void f(int);
public:
int f();
protected:
void g();
};
struct B : A {
// using A::f;
using A::g;
};
The compiler would not allow the using declaration using
A::f because void A::f(int) is not accessible
from B even though int A::f() is
accessible.