We have seen the use of the scope resolution operator (::
) to explicitly specify
the class identity of a method or state. We can also use the scope resolution operator to access global
variables, for example:
int x; class A { int x; virtual void someMethod() { x++; //increments the A::x ::x++; //increments the global x } };
What about using overloading and hiding?.. Example:
class A{ public: virtual int f(int); }; class B: public A { public: virtual int f(char *); }; int main() { B b; b.f(2); //Error - B::f(char *) hides A::f(int) b.A::f(2); //fine b.f("test"); //fine }
© 2006
Dr. Derek Molloy
(DCU).