[英]Where in the C++ Standard does it say that the definition of a const built-in type variable must be initialized?
我一直在N4713寻找这个超过两个小时无济于事。
I have a C++14 draft which says, at 7.1.6.1 [dcl.type.cv]: 我有一个C ++ 14草案,在7.1.6.1 [dcl.type.cv]中说:
As described in 8.5, the definition of an object or subobject of const-qualified type must specify an initializer or be subject to default-initialization
如8.5中所述,const限定类型的对象或子对象的定义必须指定初始化程序或受默认初始化的约束
8.5 [dcl.init] says (clause 7): 8.5 [dcl.init]说(第7条):
To default-initialize an object of type T means:
默认初始化T类型的对象意味着:
[for a non class, non array type]: [对于非类,非数组类型]:
... no initialization is performed
......没有执行初始化
And immediately follows with: 并紧接着:
If a program calls for the default initialization of an object of a const-qualified type T, T shall be a class type with a user-provided default constructor.
如果程序要求对const限定类型T的对象进行默认初始化,则T应为具有用户提供的默认构造函数的类类型。
Therefore a const
built-in must have an initializer, since otherwise it would be default-initialized and that is not allowed. 因此,
const
内置const
必须具有初始化程序,否则它将被默认初始化并且不允许。
It's worded in quite an indirect way in N4713 [dcl.init] 11.6/7: 它在N4713 [dcl.init] 11.6 / 7中以相当间接的方式措辞:
If a program calls for the default-initialization of an object of a const-qualified type
T
,T
shall be a const-default- constructible class type or array thereof.如果程序要求对const限定类型
T
的对象进行默认初始化,则T
应为const-default-constructible类类型或其数组。
Not providing an initialiser causes an object to be default-initialised. 不提供初始化会导致对象默认初始化。 As such, if it's
const
qualified and of a built-in type, it violates the "shall" rule above. 因此,如果它是
const
限定的并且是内置类型的,它违反了上面的“应该”规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.