C++练习 命名空间的使用

#include<stdlib.h>
#include<iostream>

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(void)

{
	cout << A::x << endl;
	cout << B::x << endl;
	B::fun();
	B::fun2();
	cout << "hello" << endl;
	system("pause");
	return 0;


}

运行结果:

猜你喜欢

转载自blog.csdn.net/luoyir1997/article/details/82931156
今日推荐