C++ namespace命名空间

#include <stdio.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;
    }
}

/*
int main(void)
{
    cout << A::x <<endl;
    B::fun();
    system("pause");
    return 0;

}*/

using namespace B; // 如果这里直接使用using namespace B;那么下面可以直接调用B连里面的函数。
int main(void)
{
    cout << A::x <<endl;
    fun();
    system("pause");
    return 0;

}

猜你喜欢

转载自www.cnblogs.com/chuijingjing/p/8996212.html