对于任何整数或枚举类型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.
我相信这个引用适用于直接列表初始化和复制列表初始化.
所以我认为答案是否定的,没有区别.
解决方法 如果您查看 direct initialization和 copy initialization参考资料,您会发现相同的词语: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.
我也找不到标准中的{}对应物.我希望这是足够的论据来支持没有区别的答案.
总结以上是内存溢出为你收集整理的c – 积分或枚举类型的T t {x}和T t = {x}之间的差异?全部内容,希望文章能够帮你解决c – 积分或枚举类型的T t {x}和T t = {x}之间的差异?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)