标签:
1 class C
2 {
3 int a;
4 int b;
5 public:
6 C(int i, int j);
7 };
8 C c {0,0}; //C++11 only. 相当于 C c(0,0);
9 int* a = new int[3] { 1, 2, 0 }; /C++11 only
10 class X {
11 int a[4];
12 public:
13 X() : a{1,2,3,4} {} //C++11, 初始化数组成员
14 };
1 // C++11 container initializer
2 vector vs<string>={ "first", "second", "third"};
3 map singers =
4 { {"Lady Gaga", "+1 (212) 555-7890"},
5 {"Beyonce Knowles", "+1 (212) 555-0987"}
6 };
5.类中也可以直接初始化;
1 class C
2 {
3 int a=7; //C++11 only
4 public:
5 C();
6 };
class A{ int c; };
int main()
{
A *w = new A; //new完之后的c未初始化;
A *x = new A(); //new完之后的c已初始化;
}
C++03存着这种奇怪的问题,让你有的时候用的很不放心;所以尽情用C++11吧!
标签:
原文地址:http://www.cnblogs.com/viscount/p/5842916.html