博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
namespace 相关
阅读量:7145 次
发布时间:2019-06-28

本文共 891 字,大约阅读时间需要 2 分钟。

#include <iostream>

using namespace std;
namespace first
{
int var = 5;
}
namespace second
{
double var = 3.1416;
}
int main () {
cout << first::var << endl;
cout << second::var << endl;
return 0;
}

关键字using可以帮助从namespace中引入名字到当前的声明区域

#include <iostream>

using namespace std;
namespace first
{
int x = 5;
int y = 10;
}
namespace second
{
double x = 3.1416;
double y = 2.7183;
}
int main () {
using first::x;
using second::y;
cout << x << endl;
cout << y << endl;
cout << first::y << endl;
cout << second::x << endl;
return 0;
}

using也可以导入整个的namespace

#include <iostream>

using namespace std;
namespace first
{
int x = 5;
int y = 10;
}
namespace second
{
double x = 3.1416;
double y = 2.7183;
}
int main () {
using namespace first;
cout << x << endl;
cout << y << endl;
cout << second::x << endl;
cout << second::y << endl;
return 0;
}

 

转载于:https://www.cnblogs.com/wander-clouds/p/8443188.html

你可能感兴趣的文章
工控随笔_08_西门子_Win10安装Step7.V5.6中文版授权管理器不能正常启动
查看>>
JVM垃圾收集器(1)
查看>>
wpf控件开发基础(3) -属性系统(2)
查看>>
使用cxf开发webservice接口
查看>>
在oracle中,如何当前系统时间往前推7天
查看>>
python 防死锁机制
查看>>
使有prometheus监控redis,mongodb,nginx,mysql,jmx
查看>>
数字通信原理笔记(二)---GSM系统
查看>>
使用CE找天龙八部基址(图解)毛头小伙制作
查看>>
jQuery实现的几个你可能没用过的功能
查看>>
枚举enum学习小记
查看>>
Android学习笔记之AndroidManifest.xml文件解析
查看>>
查询计划Hash和查询Hash
查看>>
『原创』让.Net CF实现智能提示(AutoComplete)功能
查看>>
Windows Phone 开发支持VB和F#了
查看>>
就我理解的递归
查看>>
oracle 11g升级
查看>>
成功杀掉病毒kpvtctr和hkvaciq
查看>>
Eclipse代码注释模板-code template
查看>>
VC操作MPP文件
查看>>