Unnamed namespaces
Unnamed namespaces
The unnamed-namespace-definition is a namespace definition of the form
inline (optional) namespace attr(optional) { namespace-body } |
|||||||||
attr(C++17) | - | optional sequence of any number of attributes |
This definition is treated as a definition of a namespace with unique name and a using-directive in the current scope that nominates this unnamed namespace.
namespace {
int i; // defines ::(unique)::i
}
void f() {
i++; // increments ::(unique)::i
} namespace A {
namespace {
int i; // A::(unique)::i
int j; // A::(unique)::j
}
void g() { i++; } // A::unique::i++
} using namespace A; // introduces all names from A into global namespace
void h() {
i++; // error: ::(unique)::i and ::A::(unique)::i are both in scope
A::i++; // ok, increments ::A::(unique)::i
j++; // ok, increments ::A::(unique)::j
}
Even though names in an unnamed namespace may be declared with external linkage, they are never accessible from other translation units because their namespace name is unique. |
(until C++11) |
Unnamed namespaces as well as all namespaces declared directly or indirectly within an unnamed namespace have internal linkage, which means that any name that is declared within an unnamed namespace has internal linkage. |
(since C++11) |
Unnamed namespaces的更多相关文章
- Google C++ Style Guide
Background C++ is one of the main development languages used by many of Google's open-source project ...
- Google开发规范
v0.2 - Last updated November 8, 2013 源自 Google's C++ coding style rev. 3.274 目录 由 DocToc生成 头文件 ...
- 转:C++ 匿名namespace的作用以及它与static的区别
匿名namespace的作用以及它与static的区别 一.匿名namespace的作用在C语言中,如果我们在多个tu(translation unit)中使用了同一个名字做为函数名或者全局变量名,则 ...
- Google C++ 代码规范
Google C++ Style Guide Table of Contents Header Files Self-contained Headers The #define Guard For ...
- C++ 匿名namespace的作用以及与static的区别
匿名namespace的作用以及它与static的区别 一.匿名namespace的作用 在C语言中,如果我们在多个tu(translation unit)中使用了同一个名字做 为函数名或者全局变量名 ...
- Google's C++ coding style
v0.2 - Last updated November 8, 2013 源自 Google's C++ coding style rev. 3.274 目录 由 DocToc生成 头文件 ...
- SWIG 3 中文手册——6. SWIG 和 C++
目录 6 SWIG 和 C++ 6.1 关于包装 C++ 6.2 方法 6.3 支持的 C++ 功能 6.4 命令行选项与编译 6.5.1 代理类的构造 6.5.2 代理类中的资源管理 6.5.3 语 ...
- Python Scopes and Namespaces
Before introducing classes, I first have to tell you something about Python's scope rules. Class def ...
- 《理解 ES6》阅读整理:函数(Functions)(二)Unnamed Parameters
使用未命名参数(Working with Unnamed Parameters) JavaScript并不限制传递给函数的实参个数,你可以总是传递比形参个数多或者少的实参.在ES6中当向函数传递比形参 ...
随机推荐
- 论文笔记系列-Neural Network Search :A Survey
论文笔记系列-Neural Network Search :A Survey 论文 笔记 NAS automl survey review reinforcement learning Bayesia ...
- openstack Q版部署-----nova服务配置-计算节点(6)
一.服务安装(计算节点) 安装软件: yum install openstack-nova-compute -y 编辑/etc/nova/nova.conf文件并设置如下内容: [DEFAULT] e ...
- jQuery实现回车绑定Tab事件
有时候我们希望回车事件绑定的是键盘的Tab事件.我的第一思路就是切换事件的keyCode,比如键盘事件按下的keyCode如果是13,我们将keyCode改为9.但是在实际编程中却未能实现此效果.于是 ...
- listView从底部回到顶部代码实现
可用如下方法: 1.平滑的回到顶部,但是会划过中间的每一页 mListView.getRefreshableView().smoothScrollToPosition(0); 2.直接跳到顶部 if ...
- [转] 解决Driver/library version mismatch
跑模型 torch.cuda.is_available()返回 False nvidia-smi返回:Failed to initialize NVML: Driver/library version ...
- vc++基础班[22]---文件的基本操作2
MFC 中的 CFile 及其派生类中没有提供直接进行文件的复制操作,因而要借助于SDK API: SDK中的文件相关函数常用的有CopyFile().CreateDirectory().Dele ...
- lvs为何不能完全替代DNS轮询
1)接入层架构要考虑的问题域为:高可用.扩展性.反向代理+扩展均衡 2)nginx.keepalived.lvs.f5可以很好的解决高可用.扩展性.反向代理+扩展均衡的问题 3)水平扩展scale o ...
- 获取日期Date
获取特定时间戳: new Date("2018-06-12").getTime() processDate(){ return { disabledDate(time){ re ...
- $Django 路由层(有,无名分组、反向解析、总路由分发、名称空间、伪静态)
1 简单配置 -第一个参数是正则表达式(如果要精准匹配:'^publish/$') -第二个参数是视图函数(不要加括号) -url(r'^admin/', admin.site.urls), 注: ...
- laravel sql复杂语句,原生写法----连表分组
### 使用了临时表.又分组又连表的感觉好难写,使用拉 ravel 但是现在越来也相信,没解决一个新的难题,自己又进步了一点点 ### 原生的sql: select user_code, realna ...