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中当向函数传递比形参 ...
随机推荐
- cubeui
1.教程项目 安装过程中出现注解
- 用v-for进行table循环
<table class="mytable mt10"> <template v-for="(item,index) in device_fault&q ...
- ORA-03113: end-of-file on communication channel 磁盘慢,数据库启动失败
磁盘慢,数据库启动失败:解决思路:1.让数据文件offline: 2.删除表空间 SQL> startup pfile='/server/oracle/admin/test/pfile/init ...
- 如何解决错误0×80071AC3
前几天我在机房敲百例的时候,敲完了想把文件夹移动到我的U盘里去,结果出现了这种情况 上面说运行chkdsk并重试,我运行了一下,没什么反应,我就想既然不能移动文件夹 ...
- HDOJ 4267 A Simple Problem with Integers (线段树)
题目: Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of opera ...
- Linux内核很吊之 module_init解析 (下)【转】
转自:https://blog.csdn.net/richard_liujh/article/details/46758073 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...
- php无法连接mysql问题解决方法总结
http://www.163ns.com/zixun/post/5295.html 本文章总结了在php开发中可能会常常碰到的一些php连接不了mysql数据库的一些问题总结与解决方法分享,有 ...
- U盘文件系统格式
u盘文件系统主要有FAT32.NTFS两种 ● FAT32文件系统 FAT32使用4个字节(也就是32位)的空间来表示每个扇区(Sector)配置文件的情形,故称之为FAT32.FAT16的分区容量上 ...
- Flash芯片你都认识吗?
[导读]Flash存储器,简称Flash,它结合了ROM和RAM的长处,不仅具备电子可擦除可编程的性能,还不会因断电而丢失数据,具有快速读取数据的特点;在现在琳琅满目的电子市场上,Flash总类可谓繁 ...
- 浅谈2017noip信息奥赛普及组试题
[话前叨叨] 一些日常刷题策略(转载): PS:本题的题目信息来自洛谷平台 下面就是进入正题了(其实这也是我第一次在csdn写博客,所以写的不好的地方也请大家多多谅解和提点/微笑/) 一.score ...