![]() |
||
| Lesson 3
Objective |
The scope resolution operator
Unary form of the scope resolution operator. |
|
|
The scope resolution operator's unary form is used to access a variable or object that is at external scope and that has been
"hidden" by an identically named variable or object declared at local or class scope.
int count = 0; //external variable void how_many(double w[], double x, int& count) { for (int i = 0; i < N; ++i) count += (w[i] == x); ++ ::count; //keep track of calls }
#include <iostream>
using namespace std;
int n = 5;
int main()
{
double n = 11.7;
cout << "Local double value of n = " << n
<< "\nGlobal int value of n = " << ::n << endl;
return 0;
}
Local double value of n = 11.7
Global int value of n = 5 |
||
|
|
||
