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中当向函数传递比形参 ...
随机推荐
- Linux 系统管理
- 使用Windows命令行启动关闭服务(net,sc用法)
下面两个命令最好以管理员方式启动cmd窗口,否则出现权限问题. 1.net用于打开没有被禁用的服务, NET命令是功能强大的以命令行方式执行的工具. 它包含了管理网络环境.服务.用户.登陆大部分重要的 ...
- oracle查询语句 select a||','||b||','||c from table where a in('m','n')
查询table表中 字段a = m 或 n 时,a列,b列,c列的值,并且这三列之间用 ","(逗号)分割. 追问:连接符的作用呢?就是显示的时候链接abc和中间的逗号么?追答:| ...
- JDK源码笔记--Object
public final native Class<?> getClass(); public native int hashCode(); public boolean equals(O ...
- 浅析 Bag of Feature
Bag of Feature 是一种图像特征提取方法,它借鉴了文本分类的思路(Bag of Words),从图像抽象出很多具有代表性的「关键词」,形成一个字典,再统计每张图片中出现的「关键词」数量,得 ...
- (转载)经典计算机视觉论文笔记——DeepFace\DeepID\DeepID2\DeepID3\FaceNet\VGGFace汇总
1. DeepFace:Closing the Gap to Human-Level Performance in Face Verification 最早将深度学习用于人脸验证的开创性工作.Face ...
- Tensorflow的Queue读取数据机制
参考链接:http://www.sohu.com/a/148245200_115128
- date命令以及date -d使用
date -d '2 days ago' //显示2天前的时间,2019年 02月 10日 星期日 08:53:28 CST date -d "2 days ago" +%Y%m% ...
- Python运维开发基础04-语法基础【转】
上节作业回顾(讲解+温习90分钟) #!/usr/bin/env python3 # -*- coding:utf-8 -*- # author:Mr.chen # 仅用列表+循环实现“简单的购物车程 ...
- Python运维开发基础01-语法基础【转】
开篇导语 整个Python运维开发教学采用的是最新的3.5.2版,当遇到2.x和3.x版本的不同点时,会采取演示的方式,让同学们了解. 教学预计分为四大部分,Python开发基础,Python开发进阶 ...