const int number{42};
这是有效的语法吗?我只能找到花括号初始化程序用于对象或非平凡类型的示例。
最佳答案
对您的问题的简单回答是YES,它是允许的并且是有效的语法。
您可以查看Uniform initialization syntax and semantics通过 stroutrup
还要根据 C++98 8.5/13 添加:
If
T
is a scalar type, then a declaration of the form
T x = { a };
is equivalent to
T x = a;
关于c++ - 基本类型的统一初始化语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25329221/