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的更多相关文章

  1. Google C++ Style Guide

    Background C++ is one of the main development languages used by many of Google's open-source project ...

  2. Google开发规范

    v0.2 - Last updated November 8, 2013 源自 Google's C++ coding style rev. 3.274 目录 由 DocToc生成     头文件   ...

  3. 转:C++ 匿名namespace的作用以及它与static的区别

    匿名namespace的作用以及它与static的区别 一.匿名namespace的作用在C语言中,如果我们在多个tu(translation unit)中使用了同一个名字做为函数名或者全局变量名,则 ...

  4. Google C++ 代码规范

    Google C++ Style Guide   Table of Contents Header Files Self-contained Headers The #define Guard For ...

  5. C++ 匿名namespace的作用以及与static的区别

    匿名namespace的作用以及它与static的区别 一.匿名namespace的作用 在C语言中,如果我们在多个tu(translation unit)中使用了同一个名字做 为函数名或者全局变量名 ...

  6. Google's C++ coding style

    v0.2 - Last updated November 8, 2013 源自 Google's C++ coding style rev. 3.274 目录 由 DocToc生成     头文件   ...

  7. 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 语 ...

  8. Python Scopes and Namespaces

    Before introducing classes, I first have to tell you something about Python's scope rules. Class def ...

  9. 《理解 ES6》阅读整理:函数(Functions)(二)Unnamed Parameters

    使用未命名参数(Working with Unnamed Parameters) JavaScript并不限制传递给函数的实参个数,你可以总是传递比形参个数多或者少的实参.在ES6中当向函数传递比形参 ...

随机推荐

  1. C/C++ 内存对齐原则及作用

    struct/class/union内存对齐原则有四个: 1).数据成员对齐规则:结构(struct)(或联合(union))的数据成员,第一个数据成员放在offset为0的地方,以后每个数据成员存储 ...

  2. Network Architecture Search Survey

  3. C# 并行循环

    Parallel.For(); Paralle.ForEach() 异步编程模式

  4. CF1100E Andrew and Taxi

    题目地址:CF1100E Andrew and Taxi 二分,每次取到一个 \(mid\) ,只保留长度 \(>mid\) 的边 dfs判环,若有环,说明 \(ans>mid\) ,否则 ...

  5. [Docker]CentOS7下Docker安装教程

    想要倒腾Kubernetes的话,第一步就是要会安装Docker,这篇文章讲一讲过程 安装步骤 检查内核版本,必须是3.10以上 uname -r 安装Docker yum -y install do ...

  6. Python3-操作系统发展史

    操作系统发展史 手工操作 —— 穿孔卡片 批处理 —— 磁带存储 多道程序系统 操作系统的作用 手工操作 —— 穿孔卡片 1946年第一台计算机诞生--20世纪50年代中期,计算机工作还在采用手工操作 ...

  7. Linux动态调频系统CPUFreq之一:概述【转】

    转自:https://blog.csdn.net/zhangyongfeiyong/article/details/53506362 随着技术的发展,我们对CPU的处理能力提出了越来越高的需求,芯片厂 ...

  8. [转] Git + LaTeX workflow

    本文取自 https://stackoverflow.com/questions/6188780/git-latex-workflow 感谢 abcd@stackoverflow Changes to ...

  9. iOS post提交数据有嵌套数组的处理方法

    2017年11月21日17:11:43 解决办法, 修改iOS框架里的代码: http://www.jianshu.com/p/130daa0c2fe7 确实有效, 要不然,  内层的每一个键值对都会 ...

  10. Kubernetes重要概念理解

    Kubernetes重要概念理解 kubernetes是目前最主流的容器编排工具,是下一代分布式架构的王者.2018年的kubernetes第一个版本1.10已经发布.下面整理一下,kubernete ...