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中当向函数传递比形参 ...
随机推荐
- 加扰与加密&解扰与解密
原文:https://blog.csdn.net/yuan892173701/article/details/8743543 加扰就是改变标准电视信号的特性,在发送端按规定处理,而加密就是在加解扰系统 ...
- C# 事务 四种事务隔离级别
http://www.zsythink.net/archives/1233 不同隔离级别的问题 脏读(Dirty Read) 一个事务处理过程里读取了另一个未提交的事务中的数据 例子: 当一个事务 ...
- linux添加swap分区【转】
概述 添加交换分区主要是因为安装oracle时碰到交换分区太小时无法安装的情况,这时候就需要添加交换分区了. 操作简介 增加swap分区方法: 1.新建磁盘分区作为swap分区 2.用文件作为swap ...
- vue之router学习笔记
1.动态路由匹配 我们经常需要将具有给定模式的路线映射到同一个组件.例如,我们可能有一个User应该为所有用户呈现但具有不同用户ID的组件.在vue-router我们可以在路径中使用动态段以实现: c ...
- Git学习笔记04-管理修改
Git跟踪并管理的是修改,而非文件.新增文件,修改一行,删除一点,都算是修改. 在.git工作区新增一个文件,test.txt,输入test git ...然后git add add之后修改t ...
- requests库入门09-OAUTH认证
实际登陆中,认证用到的token会变的,不过可以在GIthub设置一个私人token. 如图,登录GIthub,然后用户下面选择Settings/Developer settings/Personal ...
- C++ 类中特殊的成员变量(常变量、引用、静态)的初始化方法
有些成员变量的数据类型比较特别,它们的初始化方式也和普通数据类型的成员变量有所不同.这些特殊的类型的成员变量包括: a.引用 b.常量 c.静态 d.静态常量(整型) e.静态常量(非整型) 常量和引 ...
- Efuse--芯片存储
1.Efuse是什么 Efuse类似于EEPROM,是一次性可编程存储器,在芯片出场之前会被写入信息,在一个芯片中,efuse的容量通常很小,一些芯片efuse只有128bit. 2.efuse的作用 ...
- 【转】浅析SkipList跳跃表原理及代码实现
SkipList在Leveldb以及lucence中都广为使用,是比较高效的数据结构.由于它的代码以及原理实现的简单性,更为人们所接受.首先看看SkipList的定义,为什么叫跳跃表? "S ...
- 阿里云服务器上通过Docker部署redmine
背景:在日常工作的过程中会遇到各种各样的问题,每个问题来了之后需要花时间解决.这里就面临两个问题. 1:问题责任不明确,有时候会遇到数据库或者物理服务器的问题,这时候就需要把相应问题指派给相应的人,传 ...