#include <iostream>
using namespace::std;
namespace One{
int M = 200;
int inf = 10;
}
namespace Two{
int x;
int inf = 100;
}
int main()
{
// :: 是作用域运算符
cout << Two::x << endl; // x 是全局变量,自动初始化为0
Two::x = -100;
One::inf *= 1;
cout << One::inf << endl; // 10
cout << One::M << endl; // 200
Two::inf *= 2;
cout << Two::inf << endl; // 200
cout << Two::x << endl; // -100
return 0;
}
另一种形式:
int main()
{
// :: 是作用域运算符
using Two::x;
cout << x << endl; // x 是全局变量,自动初始化为0
x = -100;
using One::M;
One::inf *= 1;
cout << One::inf << endl; // 10
cout << M << endl; // 200
Two::inf *= 2;
cout << Two::inf << endl; // 200
cout << x << endl; // -100
return 0;
}