OOPortal OOPortal





C++ Class Construct  «Prev 

Redundant Scope Resolution Operator

The use of the binary form of the scope resolution operator is not usually necessary within the class definition itself or when used with memberselectors to call member functions. Take a look at this continuation of the lesson example:

widgets  w;
gizmos   g;

g.f();
w.f();
g.gizmos::f();  //legal and redundant
g.widgets::f(); //illegal widgets::f() cannot
                //act on a gizmo



Question: Why are redundant qualifications permitted on the definition?
Answer: Yes, it's allowed.
The class-name is also inserted into the scope of the class itself; this is known as the injected-class-name. For purposes of access checking, the injected-class-name is treated as if it were a public member name.