| 12345678910111213141516171819202122232425262728293031323334353637 | 
							- #include <iostream>
 
- using namespace std;
 
- #if 0
 
- int a = 10;    //全局变量
 
- void test01()
 
- {
 
-     int a = 20;//局部变量
 
-     cout << "局部变量a = " << a << endl;    //优先选择局部变量
 
-     //::作用域运算符(C++独有)
 
-     cout << "全局变量a = " << ::a << endl;   //取全局变量
 
- }
 
- #endif
 
- //定义一个名字为A的命名空间(变量、函数)
 
- namespace A {
 
-     int a = 100;
 
- }
 
- namespace B {
 
-     int a = 200;
 
- }
 
- void test02()
 
- {
 
-     //A::a a是属于A中的
 
-     cout << "namespace A中的a = " << A::a << endl;  //100
 
-     cout << "namespace B中的a = " << B::a << endl;  //200
 
- }
 
- int main()
 
- {
 
-     test02();
 
-     return 0;
 
- }
 
 
  |