inline namespace
无意中看到C++11中的新特性inline namespace, 先附上官方的解释
Inline namespace
The inline namespace mechanism is intended to support library evolution by providing a mechanism that support a form of versioning. Consider:
// file V99.h:
inline namespace V99 {
void f(int); // does something better than the V98 version
void f(double); // new feature
// ...
} // file V98.h:
namespace V98 {
void f(int); // does something
// ...
} // file Mine.h:
namespace Mine {
#include "V99.h"
#include "V98.h"
}
We here have a namespace Mine with both the latest release (V99) and the previous one (V98). If you want to be specific, you can:
#include "Mine.h"
using namespace Mine;
// ...
V98::f(); // old version
V99::f(); // new version
f(); // default version
The point is that the inline specifier makes the declarations from the nested namespace appear exactly as if they had been declared in the enclosing namespace.
This is a very ``static'' and implementer-oriented facility in that the inline specifier has to be placed by the designer of the namespaces -- thus making the choice for all users. It is not possible for a user of Mine to say ``I want the default to be V98 rather than V99.''
上面的说法大概可以这么理解,当你需要管理多个版本的类库的时候,可以用inline修饰namespace,来达到指定默认版本的目的,例如在以上的例子中 inline namespace V99 在编译的过程中会直接将里面的代码展开,就像如下的表示方式:
namespace Mine {
void f(int); // does something better than the V98 version
void f(double); // new feature // ...
// file V98.h:
namespace V98 {
void f(int); // does something
// ...
}
}
所以V99里面的方法就相当于默认的方法一样,当我们不指定命名空间直接调用 f(1); 时,就是默认调用V99里面的f();而且这个默认是我们无法去改变的,也就是说我们想调用V98里面的f(),就必须写成这样V98::f(1); 。
inline namespace的更多相关文章
- 14.inline与namespace使用
#include <iostream> using namespace std; namespace all { //inline作用为默认调用 inline namespace V201 ...
- 第一章 01 namespace 命名空间
一.什么是namespace? namesapce是为了防止名字冲突提供的一种控制方式. 当一个程序需要用到很多的库文件的时候,名字冲突有时无法避免.之前的解决思路是使用更长的变量名字,使用不方便. ...
- C++——namespace
scope和namespace scope就是我们常说的作用域,namespace是C++引入的一个关键字.这两种都和作用域有些微妙的联系,下面 引自Global scope vs global na ...
- Google C++ Style Guide
Background C++ is one of the main development languages used by many of Google's open-source project ...
- C++名字空间/C++命名空间
0.序言 名字空间是C++提供的一种解决符号名字冲突的方法. 一个命令空间是一个作用域,在不同名字空间中命名相同的符号代表不同的实体. 通常,利用定义名字空间的办法,可以使模块划分更加方便,减少模块间 ...
- C++11 FAQ中文版--转
更新至英文版October 3, 2012 译者前言: 经过C++标准委员会的不懈努力,最新的ISO C++标准C++11,也即是原来的C++0x,已经正式发布了.让我们欢迎C++11! 今天获得St ...
- Google开发规范
v0.2 - Last updated November 8, 2013 源自 Google's C++ coding style rev. 3.274 目录 由 DocToc生成 头文件 ...
- C++Primer笔记(2)
大型程序一般都是分为多个模块,由多人协作来进行开发的,其中还不可避免的会用到库.而各个模块代码以及库中会定义大量变量,而大量变量的命名,不可避免的会遇见“重名”的问题.“重名”的情况我们称之为命名空间 ...
- c++ 17介绍
作者:hearts zh链接:https://www.zhihu.com/question/32222337/answer/55238928来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商 ...
随机推荐
- compileSdkVersion,minSdkVersion 和 targetSdkVersion
compileSdkVersion(Eclipse中叫做build target) 1.在eclipse中位于项目根目录中的project.properties文件中 2.在studio中位于项目中的 ...
- java ArrayList、Vector、LinkedList区别
- Linker Scripts3--链接脚本概述
1.前言 本文主要翻译了The Link Script英文文献. (1)每个链接都是由链接脚本控制,链接脚本是用链接命令语言写的: (2)链接脚本的主要目的是描述输入文件的sections如何映射到输 ...
- English常用短语
(1) be waken by 被什么吵醒 (2) wake up ! 快醒醒 (3) put the flames /fleimz/ ...
- 【BZOJ3590】[Snoi2013]Quare 状压DP
这道题...神题. 首先看到数据范围,一眼状压 dp .然后? 没了. 理性分析,这里说断掉任意一条边图依然连通,即整个图构成一个边双(而不是点双). 之前用 fire (机房里的随机算法总称)之所以 ...
- 微信小程序-聊天列表-角标
<div class="list-body" bindtap='openChat' data-Obj='{{oitem}}'> <!-- 头像 --> &l ...
- $Django importlib与dir知识,手写配置文件, 配置查找顺序 drf分页器&drf版本控制
1 importlib与dir知识 # importlib简介动态导入字符串模块 # 常规导入 from ss.aa import b from ss import a print(b,type(b ...
- OpenStack实践系列①openstack简介及基础环境部署
OpenStack实践系列①openstack简介及基础环境部署 一.OpenStack初探1.1 OpenStack简介 OpenStack是一整套开源软件项目的综合,它允许企业或服务提供者建立.运 ...
- CodeVs 1009
题意: 给出一个整数 n(n<10^30) 和 k 个变换规则(k<=15). 规则: 一位数可变换成另一个一位数: 规则的右部不能为零. 例如:n=234.有规则(k=2): 2-> ...
- appium+java报错之nodejs报错
$ gulp(node:784) fs: re-evaluating native module sources is not supported. If you areusing the grace ...