Uniform initialization

一个 初始化列表 是一个列表, 括号 {} 初始化 可以用来初始化 简单 聚合数据类型 类实现 std: initializer_list

Uniform initialization

As noted above, C++03 is inconsistent in how it lets you initialize different types of data. Initializer lists go a long way to helping making initialization of data more consistent. However, C++11 has one more trick up its sleeve called uniform initialization. Unlike initializer lists, which take the form:

1
type variable = { data, elements };

The uniform initialization syntax takes the following form:

1
type variable { data, elements }; // note: no assignment operator

This style of initialization will work for both plain aggregate data types (structs and C-style arrays) and classes. For classes, the following rules are observed:

  • If there is an initialization_list constructor of the appropriate type, that constructor is used
  • Otherwise the class elements are initialized using the appropriate constructor

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值