forked from changkun/modern-cpp-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2.5.cpp
More file actions
34 lines (27 loc) · 529 Bytes
/
2.5.cpp
File metadata and controls
34 lines (27 loc) · 529 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// 2.5.cpp
// c++1x tutorial
//
// created by changkun at shiyanlou.com
//
// 初始化列表
#include <initializer_list>
class Foo {
private:
int value;
public:
Foo(int) {}
};
class Magic {
public:
Magic(std::initializer_list<int> list) {}
};
void func(std::initializer_list<int> list) {
return;
}
int main() {
int arr[3] = {1,2,3}; // 列表初始化
Foo foo(1); // 普通构造初始化
Magic magic = {1,2,3,4,5}; // 使用 initialize_list
func({1,2,3});
}