C++11 的发展历史
C++11 是 C++98 之后最重要的更新,标准化了既有实践并改进了抽象能力。在 ISO 于 2011 年 8 月正式采纳前,它曾被称为 C++0x。这次更新间隔长达 8 年,此后 C++ 的迭代周期才稳定为每 3 年一次。

列表初始化
C++98 传统的{}
在 C++98 中,数组和结构体可以使用花括号进行初始化,但这仅限于特定类型。
struct Point { int _x; int _y; };
int main() {
int array1[] = { 1, 2, 3, 4, 5 };
int array2[5] = { 0 };
Point p = { 1, 2 };
return 0;
}
C++11 中的{}
C++11 试图统一初始化方式,实现'一切对象皆可用{}初始化',这被称为列表初始化。它不仅支持内置类型,也支持自定义类型。对于自定义类型,本质上是构造临时对象后优化为直接构造。值得注意的是,列表初始化过程中可以省略等号 =。
#include<iostream>
#include<vector>
using namespace std;
struct P { int a; int b; };
class Date {
public:
Date(int year = 1, month = , day = ) :_year(year), _month(month), _day(day) {
cout << << endl;
}
( Date& d) :_year(d._year), _month(d._month), _day(d._day) {
cout << << endl;
}
:
_year; _month; _day;
};
{
a[] = { , , , , };
a2[] = { };
P p = { , };
x1 = { };
Date d1 = { , , };
Date& d2 = { , , };
Date d3 = { };
Date d4 = ;
P p1{ , };
x2{ };
Date d6{ , , };
Date& d7{ , , };
vector<Date> v;
v.(d1);
v.((, , ));
v.({ , , });
;
}





