gpt4 book ai didi

c++ - 带大括号的变量初始化

转载 作者:行者123 更新时间:2023-12-01 14:07:40 30 4
gpt4 key购买 nike

是以下语法:

T t = {};

对于非 POD 类型是零初始化的零初始化还是值初始化?

最佳答案

语法 T object = {arg1, arg2, ...};copy list initialization .自从您建立了T不是聚合类型,并且 T有一个默认构造函数(来自列表)然后列表初始化将执行 value initialization :

  • If T is an aggregate type, aggregate initialization is performed.
  • Otherwise, if the braced-init-list is empty and T is a class type with a default constructor, value-initialization is performed.

关于c++ - 带大括号的变量初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60696026/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com