对于任何整数或枚举类型T和任何表达式expr:
有没有区别:
struct S { T t { expr }; };
和
struct S { T t = { expr }; };
更新:
我得到[dcl.init.list] p3b5说:
If the initializer list has a single element of type E and either T is not a reference type or its referenced type is reference-related to E,the object or reference is initialized from that element.
我相信这个引用适用于直接列表初始化和复制列表初始化.
所以我认为答案是否定的,没有区别.
解决方法
if T is a non-class type,standard conversions are used,if necessary,to convert the value of other to the cv-unqualified version of T
所以应该没有区别.这些初始化的区别仅适用于类类型:复制初始化不考虑显式构造函数和显式用户定义的转换操作符,直接初始化.整体和枚举类型都没有.
编辑:
@ᐅ Johannes Schaub – litb ᐊ answered a relative question to this one(仅关于括号,而不是大括号),他引用8.5 / 14类似的措辞(强调我的):
The form of initialization (using parentheses or =) is generally
insignificant,but does matter when the initializer or the entity
being initialized has a class type; see below. If the entity being
initialized does not have class type,the expression-list in a
parenthesized initializer shall be a single expression.
我也找不到标准中的{}对应物.我希望这是足够的论据来支持没有区别的答案.