命名空间的应用示例
#include <iostream>
#include <stdlib.h>
using namespace std;
namespace A {
int x = 1;
void fun()
{
cout << "A" << endl;
}
}
namespace B {
int x = 2;
void fun()
{
cout << "B" << endl;
}
void fun2()
{
cout << "2B" << endl;
}
}
int main() {
cout << A::x << endl;
B::fun();
B::fun2();
system("pause");
return 0;
}
打印结果