简体   繁体   English

基本类型的统一初始化语法?

[英]Uniform initialization syntax for basic types?

const int number{42};

Is this valid syntax? 这是有效的语法吗? I can only find examples where the curly-brace initializers are used for objects or non-trivial types. 我只能找到花括号初始值设定项用于对象或非平凡类型的示例。

The simple answer to your question is YES it is allowed and it is a valid syntax. 你的问题的简单答案是肯定它是允许的,它是一个有效的语法。

You may check Uniform initialization syntax and semantics by stroustrup 您可以通过stroustrup检查统一初始化语法和语义

Also to add that as per C++98 8.5/13: 另外根据C ++ 98 8.5 / 13添加:

If T is a scalar type, then a declaration of the form 如果T是标量类型,则表示声明

T x = { a };

is equivalent to 相当于

T x = a;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM