Scope in C++.


The :: operator is used within C++ to identify global variables that conflict with local variable names. Obviously it would be good programming practice to use suitable names in the first place......

 #include 
 
 int Counter = 1;
 
 main() 
 {
 int Counter = 1;
 
 for (int i=0; i< 10; i++) { cout << Counter << " " << ::Counter << endl; Counter++; } return 0; } 


Examples:

o Example program.


See Also:

o C++ operators..

C References

o Global Variables.

o C Expressions and Operators.



Martin Leslie

AltStyle によって変換されたページ (->オリジナル) /