简体   繁体   English

在C ++标准中它表示必须初始化const内置类型变量的定义?

[英]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.

相关问题 内置类型的实现在哪里:c++ 中的 float/double - where is the implementation of the built-in type: float/double in c++ 在C ++标准中它说的是什么:: delete可以改变左值? - Where in the C++ Standard does it say ::delete can change lvalues? 在C ++ 14 Standard中,它表示非constexpr函数不能用于constexpr函数的定义吗? - Where in C++14 Standard does it say that a non-constexpr function cannot be used in a definition of a constexpr function? C++ - 字符串是内置数据类型吗? - C++ - Is string a built-in data type? C ++中内置类型的const修饰符的开销 - Overhead of const modifier for built-in types in C++ C ++标准在哪里说,C在哪里说相同:编译单元(.cpp文件)中的变量按声明顺序初始化 - Where does the C++ standard say, and does C say the same: variables in a compilation unit (.cpp file) are initialised in order of declaration C ++标准对于在目标类型范围之外的类型的转换结果的结果有何评价? - What does the C++ standard say about results of casting value of a type that lies outside the range of the target type? 数字和字段宽度的格式化输出,C ++标准对此有何说明? - formatted output of a number and field width, where does the C++ standard say about it? _HAVE_BOOST宏是C ++内置的吗? 它从何而来? - Is the _HAVE_BOOST macro a built-in in C++? Where does it come from? 在C ++标准中,它表示sizeof(wchar_t)<= sizeof(long)和sizeof(bool)<= sizeof(long)? - Where in the C++ Standard does it say that sizeof(wchar_t) <= sizeof(long) and sizeof(bool) <= sizeof(long)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM