#include <QCoreApplication>
#include <iostream>
using namespace std;//包含后就不用 std::cout了,直接cout
namespace ns1 {
int pram = 3;
void foo(void){
std::cout << "ns1 " << std::endl;
}
}
namespace ns2 {
int pram = 6;
}
namespace ns2 {
void foo(void){
std::cout << "ns2 " << std::endl;
}
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::cout << "233" << std::endl;
std::cout << "666!" << std::endl;
std::cout << ns1::pram << std::endl;
std::cout << ns2::pram << std::endl;
ns1::foo();
ns2::foo();
using namespace ns1;//名字空间指令
std::cout << pram << std::endl;
foo();
// using namespace ns2;//引发歧义
// std::cout << pram << std::endl;
// foo();
using ns2::pram;//名字空间声明
std::cout << pram <<std::endl;
using ns2::foo;//名字空间声明
foo();
// using ns1::foo;//名字空间声明,这里会引起歧义
// foo();
// int x,y;
// std::cin >> x >> y;
// std::cout << x << '+' << y << " = " << x + y << std::endl;
return a.exec();
}
qt开发环境 - c++之输入,输出,名字空间定义,名字空间指令,名字空间声明
于 2017-08-09 22:59:06 首次发布