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来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商 ...
随机推荐
- Django学习手册 - 连接mysql数据库
版本问题: 首先确认django.msql.python版本是统一支持 当前所用的版本信息: Django setting.py 配置 替换之前的DATABASES 配置: DATABASES = { ...
- Callable的用法示例
//Runnable是执行工作的独立任务,但是它不返回任何值.在JavaSE5中引入的Callable是一种具有类型参数的泛型,它的类型参数表的是从方法call()中返回的值,并且必须使用Execut ...
- python,os.path简单用法
#首先导入os包 import os#引入time模块是因为需要将浮点型的时间转为东八区时间 import time # basename(path),去掉路径名称,单独返回文件名 f = os.pa ...
- android屏蔽系统锁屏的办法
最近在开发一个第三方锁屏,使用中需要屏蔽系统锁屏,故代码如下: 在第三方锁屏的服务中onCreate()方法中(第三方锁屏服务启动时关闭一次系统锁屏服务即可) KeyguardManager mKey ...
- 数字图像处理的Matlab实现(1)—绪论
第1章 绪论 1.1 什么是数字图像处理 一幅图像可以定义为一个二维函数\(f(x,y)\),这里的\(x\)和\(y\)是空间坐标,而在任意坐标\((x,y)\)处的幅度\(f\)被称为这一坐标位置 ...
- Firefox is already running,实际后台查不到进程了
Firefox is already running, but is not responding. To open a new window, you must first close the ex ...
- FAT文件系统规范v1.03学习笔记---3.根目录区之FAT目录项结构
1.前言 本文主要是对Microsoft Extensible Firmware Initiative FAT32 File System Specification中文翻译版的学习笔记. 每个FAT ...
- Caching漫谈--关于Cache的几个理论【转】
转自:https://www.cnblogs.com/asis/p/cache-pattern.html 如今缓存是随处可见了,如果你的程序还没有使用到缓存,那可能是你的程序并发量很低,或对实时性要求 ...
- PHP JSON 数据解析代码
作者: 字体:[增加减小] 类型:转载 PHP解析JSON 数据代码,与大多数流行的 Web 服务如 twitter .人人网通过开放 API 来提供数据一样,它总是能够知道如何解析 API 数据 ...
- page.isvalid
背景 看到这个标题,想了半天,为啥用的.应该是当初前台要动态增加行这个事情,当初用.net真是用傻了,竟然对html.aspx原理不大清楚,对于html也想着后台生成.真是弱智啊.谈到这里,想到c#这 ...