Created
April 16, 2019 04:47
-
-
Save kangzhiheng/834c601d01aff06f0899ace0cdafec4b to your computer and use it in GitHub Desktop.
关于NULL和nullptr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
/* | |
关于NULL和nullptr | |
NULL ——> 宏定义为0(C++中, 在C中, NULL可以表示为空指针) | |
nullptr ——> 标识空指针,可以被转换成任意类型的指针和bool类型,但不能转换为整数。 | |
*/ | |
// 函数重载 | |
void func(char*) | |
{ | |
cout << "It's me!" << endl; | |
} | |
void func(int) | |
{ | |
cout << "It's you!" << endl; | |
} | |
int main() | |
{ | |
func(NULL); // 调用func(int) It's you! | |
func(nullptr); // 调用func(char*) It's me! | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
关于NULL和nullptr
NULL
——> 宏定义为0(C++中, 在C中, NULL可以表示为空指针)nullptr
——> 标识空指针,可以被转换成任意类型的指针和bool类型,但不能转换为整数。