-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy path12-nullptr-1.cpp
More file actions
49 lines (39 loc) · 1.08 KB
/
12-nullptr-1.cpp
File metadata and controls
49 lines (39 loc) · 1.08 KB
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
45
46
47
48
49
// d2mcpp: https://github.com/mcpp-community/d2mcpp
// license: Apache-2.0
// reference solution for: dslings/cpp11/12-nullptr-1.cpp
//
// 用途: 仅给 CI 与维护者参考使用,不是教程入口。
// 教程练习入口: dslings/cpp11/12-nullptr-1.cpp
//
#include <d2x/cpp/common.hpp>
bool process_int_called = false;
bool process_ptr_called = false;
bool display_int_called = false;
bool display_ptr_called = false;
void process(int* ptr) {
process_ptr_called = true;
(void)ptr;
}
void process(int value) {
process_int_called = true;
(void)value;
}
void display(int* ptr) {
display_ptr_called = true;
(void)ptr;
}
void display(int value) {
display_int_called = true;
(void)value;
}
int main() {
display(0); // -> display(int)
process(nullptr); // -> process(int*)
display(nullptr); // 用 nullptr 准确选中 display(int*)
process(0); // -> process(int)
d2x_assert(process_int_called);
d2x_assert(display_int_called);
d2x_assert(display_ptr_called);
d2x_assert(display_ptr_called);
return 0;
}