命名空间:namespace

个人认为有一点要注意:先声明命名空间,再使用 using namespace yao;

只要能出现在全局作用域中的声明就能置于命名空间内,其他的命名空间的声明也可以定义在命名空间内。即为,命名空间可以嵌套。

#include <iostream>

using namespace std;

namespace yao {
void func(int i)
{
    cout<<"yaoyang"<<endl;
}
}

namespace itcast {
void func(int i)
{
    cout<<"itcast func"<<endl;
}
}

using namespace yao;
using namespace itcast;

int main()
{
    yao::func(10);
    itcast::func(20);
    return 0;
}
发布了38 篇原创文章 · 获赞 3 · 访问量 3520

猜你喜欢

转载自blog.csdn.net/qq_38436175/article/details/104084012