// main.cpp
// demo1
//
// Created by shaun on 2018/4/30.
// Copyright © 2018年 shaun. All rights reserved.
//
#include <iostream>
// std 为默认的命名空间,缺少了,像 cout 一类的都不可用
using namespace std;
namespace A
{
int x = 1;
}
namespace B
{
int x = 2;
}
using namespace A;
void test()
{
cout << x << endl;
}
int main()
{
cout << A::x << endl;
cout << B::x << endl;
cout << "Hello, world!" << endl;
test();
return 0;
}
A::x 类似于 A.x ,运行结果:
1
2
Hello, world!
1
Program ended with exit code: 0
网友评论