在静态上使用未命名的名称空间 [英] Use of Unnamed namespace over static
本文介绍了在静态上使用未命名的名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以假定在未命名的命名空间中声明的对象等同于static
吗?
Can I assume an object declared in unnamed namespace to be equivalent to as if were static
?
namespace { int x; };// #1
static int x; // #2
FWIK,在两种情况下,x
将具有静态存储持续时间和内部链接.
那么,声明为static
的对象的所有规则是否适用于未命名命名空间中的对象?
FWIK, In both cases, x
will have static storage duration and internal linkage.
So does all the rules of an object declared as static
applies to an object in unnamed namespace?
例如:
- 构造和破坏的顺序是什么?会一样吗?
- 我可以在未命名的命名空间中将
extern
关键字与x
一起使用吗?
- What will be the order of construction and destruction? will it be same?
- Can I use
extern
keyword withx
in unnamed namespace?
推荐答案
查看全文