Scope Resolution Operator ::

The :: (scope resolution) operator is used to qualify hidden names so that you can still use them. You can use the unary scope operator if a file scope name is hidden by an explicit declaration of the same name in a block or class. For example:

int i = 10;
int f(int i)
{
      return i ? i : :: i; // return global i if local i is zero
}

You can also use the class scope operator to qualify class names or class member names. If a class member name is hidden, you can use it by qualifying it with its class name and the class scope operator. Whenever a name is followed by a :: operator, the name is interpreted as a class name.

In the following example, the declaration of the variable X hides the class type X, but you can still use the static class member count by qualifying it with the class type X and the scope resolution operator.

#include <iostream.h>
class X
{
public:
      static int count;
};
int X::count = 10;                // define static data member
void main ()
{
      int X = 0;                  // hides class type X
      cout << X::count << endl;   // use static member of class X
}


Scope of Class Names


Class Names