initializer-list和列表初始化

C++11的列表初始化

在C语言和C++98/03中,大括号可以用来初始化数组,例如:

int a[] = {1, 2, 3};
int b[4] = {1, 2, 3, 4}; // 如果个数不足的,用0初始化

C++11将这类大括号初始化,扩展到自定义类型,但需要满足一定的条件,否则会编译报错。

参考C++11新特性之列表初始化、POD、聚合类

  1. C++98/03标准中对于普通数组和POD类型可以直接使用列表初始化;
  2. C++11标准中对于普通数组和聚合类型可以直接使用列表初始化;
  3. C++11标准中对于非聚合类型可以通过自定义构造函数的方式使用列表初始化。

C++11新特性之列表初始化提到非聚合类型不能使用列表初始化是不对的。实验证明,不论是不是聚合类型,均可以采用列表初始化。

class A {
	public:
		A(int a1) {}
		A(std::initializer_list<int> l) {}
	private:
		int a {12};
};
int main()
{
	A a = {123};
    ...
}

首先声明A a={123}或者A a{123}这两种构造方法是一致的。
其次,对于这种构造方法,编译器会先尝试用A(std::initializer_list<int> l)去匹配,如果不成功,则会尝试A(int),如果这两种构造函数都未定义,就会编译报错。
另外,成员变量也可以采用就地初始化, 虽然这会导致类成为非聚合类,但并不妨碍其采用列表初始化方法。使用虚函数,有基类的效果都是一样的,不影响列表初始化方法的使用。

C++11中的几种初始化方法

  1. 就地初始化
class A {
	private:
		int a1 {12};
        double a2 = {12.0};
        float a3 = 12.0
        B b{123}
        C c = {123};
};
  1. 构造函数初始化列表
class A {
    public:
        A() : a(123), b(456) {}
	private:
        int a;
        int b;
};
  1. 列表初始化
class A {
    public:
        A(int, int) {}
        A(std::initializer_list<int, int>) {}
	private:
        int a;
        int b;
};
void main ()
{
    // 优先匹配A(std::initializer_list<int, int>)
    // 再匹配A(int, int)
    // 否则报错
    A a {123, 456};
}
  • 就地初始化会最先得到执行,构造函数初始化列表会覆盖就地初始化的值
  • 如果采用初始化列表,即a{...}初始化,std::initializer_list<T>的构造函数会优先得到执行
  • 如果采用原生构造函数,即a(int)初始化,A(init)优先得到执行

什么是initializer-list

摘录C++11新特性之列表初始化-初始化列表

  1. 它是一个轻量级的容器类型,内部定义了迭代器iterator等容器必须的一些概念。
  2. initialzer-list<T>来说,它可以接受任意长度的初始化列表,但是元素必须是要相同的或者可以转换为T类型的。
  3. 三个成员接口,begin(),end(),size(),其中size()返回initialzer-list的长度。
  4. 能被整体的初始化和赋值,遍历只能通过begin和end迭代器来,遍历取得的数据是可读的,是不能对单个进行修改的。

注意一:
initialzer-list<T>保存的是T类型的引用,并不对T类型的数据进行拷贝,因此需要注意变量的生存期

std::initializer_list<int> func(void)
{
    return{ 2, 3 };
}
void main()
{
    auto c = func();
    for (auto it = c.begin(); it != c.end(); it++)
		std::cout << it - c.begin() << ":" << (*it) << std::endl;
}

此处打印是乱的。因为func返回的是右值引用,在退出函数后失效。

注意二:
列表初始化防止类型收窄

int a = 1.1; //OK
int b{ 1.1 }; //error
 
float f1 = 1e40; //OK, 科学计数法10^40
float f2{ 1e40 }; //error
 
const int x = 1024, y = 1;
char c = x; //OK
char d{ x };//error
char e = y;//error
char f{ y };//error

参考文献

initializer_list - cppreference.com

C++11新特性之列表初始化

C++11新特性之列表初始化、POD、聚合类

%23%20C%2B%2B11%E7%9A%84%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%0A%E5%9C%A8C%E8%AF%AD%E8%A8%80%E5%92%8CC%2B%2B98%2F03%E4%B8%AD%EF%BC%8C%E5%A4%A7%E6%8B%AC%E5%8F%B7%E5%8F%AF%E4%BB%A5%E7%94%A8%E6%9D%A5%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E7%BB%84%EF%BC%8C%E4%BE%8B%E5%A6%82%EF%BC%9A%0A%60%60%60c%0Aint%20a%5B%5D%20%3D%20%7B1%2C%202%2C%203%7D%3B%0Aint%20b%5B4%5D%20%3D%20%7B1%2C%202%2C%203%2C%204%7D%3B%20%2F%2F%20%E5%A6%82%E6%9E%9C%E4%B8%AA%E6%95%B0%E4%B8%8D%E8%B6%B3%E7%9A%84%EF%BC%8C%E7%94%A80%E5%88%9D%E5%A7%8B%E5%8C%96%0A%60%60%60%0A%0AC%2B%2B11%E5%B0%86%E8%BF%99%E7%B1%BB%E5%A4%A7%E6%8B%AC%E5%8F%B7%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%8C%E6%89%A9%E5%B1%95%E5%88%B0%E8%87%AA%E5%AE%9A%E4%B9%89%E7%B1%BB%E5%9E%8B%EF%BC%8C%E4%BD%86%E9%9C%80%E8%A6%81%E6%BB%A1%E8%B6%B3%E4%B8%80%E5%AE%9A%E7%9A%84%E6%9D%A1%E4%BB%B6%EF%BC%8C%E5%90%A6%E5%88%99%E4%BC%9A%E7%BC%96%E8%AF%91%E6%8A%A5%E9%94%99%E3%80%82%0A%3E%E5%8F%82%E8%80%83%5BC%2B%2B11%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%81POD%E3%80%81%E8%81%9A%E5%90%88%E7%B1%BB%5D(https%3A%2F%2Fblog.csdn.net%2FJinhuCheng%2Farticle%2Fdetails%2F107330983)%0A%3E%201.%20C%2B%2B98%2F03%E6%A0%87%E5%87%86%E4%B8%AD%E5%AF%B9%E4%BA%8E%E6%99%AE%E9%80%9A%E6%95%B0%E7%BB%84%E5%92%8CPOD%E7%B1%BB%E5%9E%8B%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E4%BD%BF%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%9B%0A%3E%202.%20C%2B%2B11%E6%A0%87%E5%87%86%E4%B8%AD%E5%AF%B9%E4%BA%8E%E6%99%AE%E9%80%9A%E6%95%B0%E7%BB%84%E5%92%8C%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E4%BD%BF%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%9B%0A%3E%203.%20C%2B%2B11%E6%A0%87%E5%87%86%E4%B8%AD%E5%AF%B9%E4%BA%8E%E9%9D%9E%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E8%87%AA%E5%AE%9A%E4%B9%89%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E7%9A%84%E6%96%B9%E5%BC%8F%E4%BD%BF%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%82%0A%5BC%2B%2B11%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%5D(https%3A%2F%2Fblog.csdn.net%2Fhailong0715%2Farticle%2Fdetails%2F54018002)%E6%8F%90%E5%88%B0%E9%9D%9E%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%E4%B8%8D%E8%83%BD%E4%BD%BF%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E6%98%AF%E4%B8%8D%E5%AF%B9%E7%9A%84%E3%80%82%E5%AE%9E%E9%AA%8C%E8%AF%81%E6%98%8E%EF%BC%8C%E4%B8%8D%E8%AE%BA%E6%98%AF%E4%B8%8D%E6%98%AF%E8%81%9A%E5%90%88%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%9D%87%E5%8F%AF%E4%BB%A5%E9%87%87%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%82%0A%60%60%60c%2B%2B%0Aclass%20A%20%7B%0A%09public%3A%0A%09%09A(int%20a1)%20%7B%7D%0A%09%09A(std%3A%3Ainitializer_list%3Cint%3E%20l)%20%7B%7D%0A%09private%3A%0A%09%09int%20a%20%7B12%7D%3B%0A%7D%3B%0Aint%20main()%0A%7B%0A%09A%20a%20%3D%20%7B123%7D%3B%0A%20%20%20%20...%0A%7D%0A%60%60%60%0A%E9%A6%96%E5%85%88%E5%A3%B0%E6%98%8E%60A%20a%3D%7B123%7D%60%E6%88%96%E8%80%85%60A%20a%7B123%7D%60%E8%BF%99%E4%B8%A4%E7%A7%8D%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%E6%98%AF%E4%B8%80%E8%87%B4%E7%9A%84%E3%80%82%0A%E5%85%B6%E6%AC%A1%EF%BC%8C%E5%AF%B9%E4%BA%8E%E8%BF%99%E7%A7%8D%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%EF%BC%8C%E7%BC%96%E8%AF%91%E5%99%A8%E4%BC%9A%E5%85%88%E5%B0%9D%E8%AF%95%E7%94%A8%60A(std%3A%3Ainitializer_list%3Cint%3E%20l)%60%E5%8E%BB%E5%8C%B9%E9%85%8D%EF%BC%8C%E5%A6%82%E6%9E%9C%E4%B8%8D%E6%88%90%E5%8A%9F%EF%BC%8C%E5%88%99%E4%BC%9A%E5%B0%9D%E8%AF%95%60A(int)%60%EF%BC%8C%E5%A6%82%E6%9E%9C%E8%BF%99%E4%B8%A4%E7%A7%8D%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E9%83%BD%E6%9C%AA%E5%AE%9A%E4%B9%89%EF%BC%8C%E5%B0%B1%E4%BC%9A%E7%BC%96%E8%AF%91%E6%8A%A5%E9%94%99%E3%80%82%0A%E5%8F%A6%E5%A4%96%EF%BC%8C%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E4%B9%9F%E5%8F%AF%E4%BB%A5%E9%87%87%E7%94%A8%E5%B0%B1%E5%9C%B0%E5%88%9D%E5%A7%8B%E5%8C%96%2C%20%E8%99%BD%E7%84%B6%E8%BF%99%E4%BC%9A%E5%AF%BC%E8%87%B4%E7%B1%BB%E6%88%90%E4%B8%BA%E9%9D%9E%E8%81%9A%E5%90%88%E7%B1%BB%EF%BC%8C%E4%BD%86%E5%B9%B6%E4%B8%8D%E5%A6%A8%E7%A2%8D%E5%85%B6%E9%87%87%E7%94%A8%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E6%96%B9%E6%B3%95%E3%80%82%E4%BD%BF%E7%94%A8%E8%99%9A%E5%87%BD%E6%95%B0%EF%BC%8C%E6%9C%89%E5%9F%BA%E7%B1%BB%E7%9A%84%E6%95%88%E6%9E%9C%E9%83%BD%E6%98%AF%E4%B8%80%E6%A0%B7%E7%9A%84%EF%BC%8C%E4%B8%8D%E5%BD%B1%E5%93%8D%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E6%96%B9%E6%B3%95%E7%9A%84%E4%BD%BF%E7%94%A8%E3%80%82%0A%23%23%20C%2B%2B11%E4%B8%AD%E7%9A%84%E5%87%A0%E7%A7%8D%E5%88%9D%E5%A7%8B%E5%8C%96%E6%96%B9%E6%B3%95%0A1.%20%E5%B0%B1%E5%9C%B0%E5%88%9D%E5%A7%8B%E5%8C%96%0A%60%60%60c%2B%2B%0Aclass%20A%20%7B%0A%09private%3A%0A%09%09int%20a1%20%7B12%7D%3B%0A%20%20%20%20%20%20%20%20double%20a2%20%3D%20%7B12.0%7D%3B%0A%20%20%20%20%20%20%20%20float%20a3%20%3D%2012.0%0A%20%20%20%20%20%20%20%20B%20b%7B123%7D%0A%20%20%20%20%20%20%20%20C%20c%20%3D%20%7B123%7D%3B%0A%7D%3B%0A%60%60%60%0A2.%20%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%0A%60%60%60c%2B%2B%0Aclass%20A%20%7B%0A%20%20%20%20public%3A%0A%20%20%20%20%20%20%20%20A()%20%3A%20a(123)%2C%20b(456)%20%7B%7D%0A%09private%3A%0A%20%20%20%20%20%20%20%20int%20a%3B%0A%20%20%20%20%20%20%20%20int%20b%3B%0A%7D%3B%0A%60%60%60%0A3.%20%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%0A%60%60%60c%2B%2B%0Aclass%20A%20%7B%0A%20%20%20%20public%3A%0A%20%20%20%20%20%20%20%20A(int%2C%20int)%20%7B%7D%0A%20%20%20%20%20%20%20%20A(std%3A%3Ainitializer_list%3Cint%2C%20int%3E)%20%7B%7D%0A%09private%3A%0A%20%20%20%20%20%20%20%20int%20a%3B%0A%20%20%20%20%20%20%20%20int%20b%3B%0A%7D%3B%0Avoid%20main%20()%0A%7B%0A%20%20%20%20%2F%2F%20%E4%BC%98%E5%85%88%E5%8C%B9%E9%85%8DA(std%3A%3Ainitializer_list%3Cint%2C%20int%3E)%0A%20%20%20%20%2F%2F%20%E5%86%8D%E5%8C%B9%E9%85%8DA(int%2C%20int)%0A%20%20%20%20%2F%2F%20%E5%90%A6%E5%88%99%E6%8A%A5%E9%94%99%0A%20%20%20%20A%20a%20%7B123%2C%20456%7D%3B%0A%7D%0A%60%60%60%0A-%20%E5%B0%B1%E5%9C%B0%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BC%9A%E6%9C%80%E5%85%88%E5%BE%97%E5%88%B0%E6%89%A7%E8%A1%8C%EF%BC%8C%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%E4%BC%9A%E8%A6%86%E7%9B%96%E5%B0%B1%E5%9C%B0%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E5%80%BC%0A-%20%E5%A6%82%E6%9E%9C%E9%87%87%E7%94%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%EF%BC%8C%E5%8D%B3%60a%7B...%7D%60%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%8C%60std%3A%3Ainitializer_list%3CT%3E%60%E7%9A%84%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E4%BC%9A%E4%BC%98%E5%85%88%E5%BE%97%E5%88%B0%E6%89%A7%E8%A1%8C%0A-%20%E5%A6%82%E6%9E%9C%E9%87%87%E7%94%A8%E5%8E%9F%E7%94%9F%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%EF%BC%8C%E5%8D%B3%60a(int)%60%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%8C%60A(init)%60%E4%BC%98%E5%85%88%E5%BE%97%E5%88%B0%E6%89%A7%E8%A1%8C%0A%23%20%E4%BB%80%E4%B9%88%E6%98%AFinitializer-list%0A%3E**%E6%91%98%E5%BD%95%5BC%2B%2B11%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%5D(https%3A%2F%2Fblog.csdn.net%2Fhailong0715%2Farticle%2Fdetails%2F54018002)**-%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%0A%3E1.%20%E5%AE%83%E6%98%AF%E4%B8%80%E4%B8%AA%E8%BD%BB%E9%87%8F%E7%BA%A7%E7%9A%84%E5%AE%B9%E5%99%A8%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%86%85%E9%83%A8%E5%AE%9A%E4%B9%89%E4%BA%86%E8%BF%AD%E4%BB%A3%E5%99%A8iterator%E7%AD%89%E5%AE%B9%E5%99%A8%E5%BF%85%E9%A1%BB%E7%9A%84%E4%B8%80%E4%BA%9B%E6%A6%82%E5%BF%B5%E3%80%82%20%0A%3E2.%20initialzer-list%3CT%3E%E6%9D%A5%E8%AF%B4%EF%BC%8C%E5%AE%83%E5%8F%AF%E4%BB%A5%E6%8E%A5%E5%8F%97%E4%BB%BB%E6%84%8F%E9%95%BF%E5%BA%A6%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%EF%BC%8C%E4%BD%86%E6%98%AF%E5%85%83%E7%B4%A0%E5%BF%85%E9%A1%BB%E6%98%AF%E8%A6%81%E7%9B%B8%E5%90%8C%E7%9A%84%E6%88%96%E8%80%85%E5%8F%AF%E4%BB%A5%E8%BD%AC%E6%8D%A2%E4%B8%BAT%E7%B1%BB%E5%9E%8B%E7%9A%84%E3%80%82%20%20%0A%3E3.%20%E4%B8%89%E4%B8%AA%E6%88%90%E5%91%98%E6%8E%A5%E5%8F%A3%EF%BC%8Cbegin()%2Cend()%2Csize()%2C%E5%85%B6%E4%B8%ADsize()%E8%BF%94%E5%9B%9Einitialzer-list%E7%9A%84%E9%95%BF%E5%BA%A6%E3%80%82%20%20%0A%3E4.%20%E8%83%BD%E8%A2%AB%E6%95%B4%E4%BD%93%E7%9A%84%E5%88%9D%E5%A7%8B%E5%8C%96%E5%92%8C%E8%B5%8B%E5%80%BC%EF%BC%8C%E9%81%8D%E5%8E%86%E5%8F%AA%E8%83%BD%E9%80%9A%E8%BF%87begin%E5%92%8Cend%E8%BF%AD%E4%BB%A3%E5%99%A8%E6%9D%A5%EF%BC%8C%E9%81%8D%E5%8E%86%E5%8F%96%E5%BE%97%E7%9A%84%E6%95%B0%E6%8D%AE%E6%98%AF%E5%8F%AF%E8%AF%BB%E7%9A%84%EF%BC%8C%E6%98%AF%E4%B8%8D%E8%83%BD%E5%AF%B9%E5%8D%95%E4%B8%AA%E8%BF%9B%E8%A1%8C%E4%BF%AE%E6%94%B9%E7%9A%84%E3%80%82%20%20%0A%0A%E6%B3%A8%E6%84%8F%E4%B8%80%EF%BC%9A%0Ainitialzer-list%3CT%3E%E4%BF%9D%E5%AD%98%E7%9A%84%E6%98%AFT%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%BC%95%E7%94%A8%EF%BC%8C%E5%B9%B6%E4%B8%8D%E5%AF%B9T%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%95%B0%E6%8D%AE%E8%BF%9B%E8%A1%8C%E6%8B%B7%E8%B4%9D%EF%BC%8C%E5%9B%A0%E6%AD%A4%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%E5%8F%98%E9%87%8F%E7%9A%84%E7%94%9F%E5%AD%98%E6%9C%9F%0A%60%60%60c%2B%2B%0Astd%3A%3Ainitializer_list%3Cint%3E%20func(void)%0A%7B%0A%20%20%20%20return%7B%202%2C%203%20%7D%3B%0A%7D%0Avoid%20main()%0A%7B%0A%20%20%20%20auto%20c%20%3D%20func()%3B%0A%20%20%20%20for%20(auto%20it%20%3D%20c.begin()%3B%20it%20!%3D%20c.end()%3B%20it%2B%2B)%0A%09%09std%3A%3Acout%20%3C%3C%20it%20-%20c.begin()%20%3C%3C%20%22%3A%22%20%3C%3C%20(*it)%20%3C%3C%20std%3A%3Aendl%3B%0A%7D%0A%60%60%60%0A%E6%AD%A4%E5%A4%84%E6%89%93%E5%8D%B0%E6%98%AF%E4%B9%B1%E7%9A%84%E3%80%82%E5%9B%A0%E4%B8%BAfunc%E8%BF%94%E5%9B%9E%E7%9A%84%E6%98%AF%E5%8F%B3%E5%80%BC%E5%BC%95%E7%94%A8%EF%BC%8C%E5%9C%A8%E9%80%80%E5%87%BA%E5%87%BD%E6%95%B0%E5%90%8E%E5%A4%B1%E6%95%88%E3%80%82%0A%0A%E6%B3%A8%E6%84%8F%E4%BA%8C%EF%BC%9A%0A%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E9%98%B2%E6%AD%A2%E7%B1%BB%E5%9E%8B%E6%94%B6%E7%AA%84%0A%60%60%60c%2B%2B%0Aint%20a%20%3D%201.1%3B%20%2F%2FOK%0Aint%20b%7B%201.1%20%7D%3B%20%2F%2Ferror%0A%20%0Afloat%20f1%20%3D%201e40%3B%20%2F%2FOK%2C%20%E7%A7%91%E5%AD%A6%E8%AE%A1%E6%95%B0%E6%B3%9510%5E40%0Afloat%20f2%7B%201e40%20%7D%3B%20%2F%2Ferror%0A%20%0Aconst%20int%20x%20%3D%201024%2C%20y%20%3D%201%3B%0Achar%20c%20%3D%20x%3B%20%2F%2FOK%0Achar%20d%7B%20x%20%7D%3B%2F%2Ferror%0Achar%20e%20%3D%20y%3B%2F%2Ferror%0Achar%20f%7B%20y%20%7D%3B%2F%2Ferror%0A%60%60%60%0A%0A%0A%23%20%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%0A%5Binitializer_list%20-%20cppreference.com%5D(https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Futility%2Finitializer_list)%0A%5BC%2B%2B11%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%5D(https%3A%2F%2Fblog.csdn.net%2Fhailong0715%2Farticle%2Fdetails%2F54018002)%0A%5BC%2B%2B11%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E5%88%97%E8%A1%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E3%80%81POD%E3%80%81%E8%81%9A%E5%90%88%E7%B1%BB%5D(https%3A%2F%2Fblog.csdn.net%2FJinhuCheng%2Farticle%2Fdetails%2F107330983)