命名空间
//命名空间
//1.命名空间是用来组织和重用代码的编译单元
//2.在编写代码时写的程序不可能所有的标识符都没有重名现象
//在很多人协同开发时更加不可控制,尤其对于库来说问题更加严重、。
//为了解重名现象,通过命名空间来避免冲突
#include<iostream>
//using namespace std;
//封装 命名空间里面的东西默认时对外时不开放的
//namespace YIMU
//{
// int sum = 10;
// void fun1()
// {
// cout << "hello world!" << endl;
// }
// void fun2()
// {
// cout << sum << endl;
// }
// namespace A
// {
// void fun3()
// {
// cout << "adsf" << endl;
// }
// }
//}
//using namespace YIMU;//把命名空间中的所有成员对外公开
//把YIMU命名空间下的fun2对外开放
//using YIMU::fun2;//::理解为哪个空间下的什么
//using namespace YIMU::A;//只打开了A 而不是A和YIMU都打开了
#include"tool.h"
using namespace AAAAAA;
int main()
{
//fun1();
//fun2();
//cout << sum << endl;
//fun3();
//YIMU::A::fun3();//打开YIMU下面的A中的fun3();
fun();
system("pause");
}
//头文件tool.h
#pragma once
#include<iostream>
using namespace std;
namespace AAAAAA
{
void fun();//函数的声明
}
//与头文件同名的文件tool.cpp
#include"tool.h"
//函数体
void AAAAAA::fun()
{
cout << "qwer" << endl;
}