Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
const int number{42};
这是有效的语法吗?我只能找到花括号初始值设定项用于对象或非平凡类型的示例。
您的问题的简单答案是“是”,它是允许的,并且它是有效的语法。
您可以通过 stroustrup检查统一初始化语法和语义
还要根据 C++98 8.5/13 添加:
如果T是标量类型,则声明形式
T
T x = { a };
相当于
T x = a;