C++命名空间

/*示例程序*/
#include <iostream>
namespace variable //命名空间variable
{
    int x=10;
    namespace function //内部嵌套命名空间function
    {
        void show();
    }
}
void variable::function::show()//命名空间外部定义
{
    std::cout<<x<<std::endl;//可以直接访问上一级的变量
}
using namespace variable::function;//声明使用的namespace;
int main()
{
    show();
    //variable::function::show();
    return 0;
}

  

原文地址:https://www.cnblogs.com/tinaluo/p/6288392.html