forked from mcpp-community/d2mcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09-list-initialization-1.cpp
More file actions
44 lines (36 loc) · 989 Bytes
/
09-list-initialization-1.cpp
File metadata and controls
44 lines (36 loc) · 989 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
35
36
37
38
39
40
41
42
43
44
// d2mcpp: https://github.com/mcpp-community/d2mcpp
// license: Apache-2.0
// file: dslings/cpp11/09-list-initialization-1.cpp
//
// Exercise/练习: cpp11 | 09 - list initialization | 默认初始化语法陷阱
//
// Tips/提示: 根据编译器的输出, 修复编译器报错, 了解默认初始化语法陷阱
//
// Docs/文档:
// - https://en.cppreference.com/w/cpp/language/list_initialization.html
// - https://github.com/mcpp-community/d2mcpp/blob/main/book/src/cpp11/09-list-initialization.md
//
// Auto-Checker/自动检测命令:
//
// d2x checker list-initialization
//
#include <d2x/cpp/common.hpp>
#include <iostream>
struct Object {
Object() {
x = 0;
std::cout << "Object()" << std::endl;
}
Object(int x) : x(x) {
std::cout << "Object(int): " << x << std::endl;
}
int x;
};
int main() {
Object obj1();
Object obj2(2);
d2x_assert_eq(obj1.x, 0);
d2x_assert_eq(obj2.x, 2);
D2X_WAIT
return 0;
}