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中当向函数传递比形参 ...
随机推荐
- 关于setInterval返回值问题
oBtn1.onclick = function(){ clearInterval(timer); timer = setInterval(cwidth,10); alert(timer); } oB ...
- pythonの递归锁
首先看一个例子,让我们lock = threading.Lock() 时(代码第33行),程序会卡死在这里 #!/usr/bin/env python import threading,time de ...
- SpringSecurity项目中如何在多个模块中配置认证信息
⒈在SpringSecurity项目中创建AuthorizeConfigProvider接口用于配置认证信息 package cn.coreqi.ssoserver.authorize; import ...
- CAN总线芯片SN65HVD230QD介绍
CAN总线硬件电路如上,采用芯片为SN65HVD230QD,从TI获得的芯片手册,可知该芯片参数为: 3.3V供电 低电流为370uA典型值
- 数据库join union 区别
join 是两张表做交连后里面条件相同的部分记录产生一个记录集,union是产生的两个记录集(字段要一样的)并在一起,成为一个新的记录集. 1.JOIN和UNION区别 join 是两张表做交连后里 ...
- linux 常用的中文手册
http://linuxtools-rst.readthedocs.io/zh_CN/latest/base/index.html 总结的非常好!包括基础.进阶以及各种常用工具.
- 常用的ORM框架
现在,很多项目使用ORM的框架构架实现数据持久层,下面列举一些常用的ORM框架有,后续分节介绍. Java:Hibernate和Mybatis(前身iBatis) .Net:EF6与EFCore.Da ...
- python学习第天14天。
模块 什么是模块 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写的代码( ...
- log4net 全局配置
public class LogHelper { private static readonly log4net.ILog ILogInfo = log4net.LogManager.GetLogge ...
- php 汉字的首字母
<?php//php获取中文字符拼音首字母function getFirstCharter($str){ if(empty($str)) { return ''; } $fchar=ord($s ...