int count = 0;
int main(void) {
int count = 0;
::count = 1; // set global count to 1
count = 2; // set local count to 2
return 0;
}
The declaration of count declared in the main function
hides the integer named count declared in global namespace
scope. The statement ::count = 1 accesses the variable named count declared
in global namespace scope.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.
#include <iostream>
using namespace std;
class X
{
public:
static int count;
};
int X::count = 10; // define static data member
int main ()
{
int X = 0; // hides class type X
cout << X::count << endl; // use static member of class X
}