NULL
| Defined in header <cstddef> |  |  | 
|---|---|---|
| Defined in header <cstring> |  |  | 
| Defined in header <cwchar> |  |  | 
| Defined in header <ctime> |  |  | 
| Defined in header <cstdio> |  |  | 
| Defined in header <clocale> |  |  | 
| Defined in header <cstdlib> |  |  | 
| #define NULL /*implementation-defined*/ |  |  | 
宏NULL是实现定义的空指针常量,它可能是。
| an integral constant expression rvalue of integer type that evaluates to zero. | (until C++11) | 
|---|---|
| an integer literal with value zero, or a prvalue of type std::nullptr_t. | (since C++11) | 
空指针常量可能是隐式转换指向任何指针类型;这种转换将导致该类型的空指针值。如果空指针常量具有整数类型,则可以将其转换为类型的prvalue。std::nullptr_t...
可能的实施
#定义空0//自C++11#定义空nullptr
*。
注记
在C中,宏NULL可能有这种类型void*,但这在C++中是不允许的。
例
二次
#include <cstddef>
class S;
int main()
{
    int* p = NULL;
    int* p2 = static_cast<std::nullptr_t>(NULL);
    void(*f)(int) = NULL;
    int S::*mp = NULL;
    void(S::*mfp)(int) = NULL;
}二次
缺陷报告
以下行为更改缺陷报告追溯应用于先前发布的C++标准。
| DR | Applied to | Behavior as published | Correct behavior | 
|---|---|---|---|
| CWG 903 | C++11 | constant expressions with zero value such as 1-1 were allowed | only the literal zero is allowed | 
另见
| nullptr | the pointer literal which specifies a null pointer value (C++11) | 
|---|---|
| nullptr_t (C++11) | the type of the null pointer literal nullptr (typedef) | 
C文档为NULL
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

