forked from changkun/modern-cpp-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2.1.cpp
More file actions
32 lines (26 loc) · 605 Bytes
/
2.1.cpp
File metadata and controls
32 lines (26 loc) · 605 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
//
// 2.1.cpp
// c++1x tutorial
//
// created by changkun at shiyanlou.com
//
// nullptr
#include <iostream>
void foo(char *);
void foo(int);
int main() {
if(NULL == (void *)0)
std::cout << "NULL == 0" << std::endl; // 该行将输出
else
std::cout << "NULL != 0" << std::endl;
foo(0); // 调用 foo(int)
//foo(NULL); // 该行不能通过编译
foo(nullptr); // 调用 foo(char*)
return 0;
}
void foo(char *ch) {
std::cout << "call foo(char*)" << std::endl;
}
void foo(int i) {
std::cout << "call foo(int)" << std::endl;
}