nullptr是什么类型?
我知道是编译器关键字
但是和std::nullptr_t有和关系?
[解决办法]
CLR ?
nullptr indicates that an object handle, interior pointer, or native pointer type does not point to an object. nullptr is only valid when compiling with /clr (Common Language Runtime Compilation).
You cannot initialize handles to zero; only nullptr can be used. Assignment of constant 0 to an object handle will produce a boxed Int32 and a cast to Object^.
nullptr can be used in the initialization of the following pointer types:
Native pointer:
Managed handle:
Managed interior pointer:
nullptr can be used for reference checking before using a pointer.
nullptr can be used anywhere a handle or a native pointer can be used. nullptr can also be used as an argument for functions.
[解决办法]
nullptr是C++11关键字,表示空指针。std::nullptr_t就是nullptr的类型。
[解决办法]
[解决办法]
我记得在不同的cpu架构下,空指针的定义是不一样的,有些是指向地址0,有些是指向0xFFFFFFFF.
[解决办法]
作为c++标准控,我用c++标准回答你。
c++11标准:
1. nullptr是一个字面值常量,类型为std::nullptr_t。(如果你不懂,对比一下:12是一个字面值常量,类型为int,123.0 是一个字面值常量,类型为double)。
2. nullptr和0统称为空指针常数。注意下面这一点:空指针常数可以转换为任意类型的指针类型。
int *a = 0; //ok,可以转换
int *b = nullptr; //ok,可以转换
3. 两个空指针相等;
nullptr==0 //true
4. 0可以转换为std::nullptr_t
std::nullptr_t a = nullptr; //ok
std::nullptr_t b = 0; //ok
5. std::nullptr_t类型不可以转换到0
int a = nullptr; //错误
6. std::nullptr_t可以转换到bool,值为false
if (nullptr) {
} else {
//nullptr 为false,所以执行这里。
}
[解决办法]
你可以认为nullptr的类型是任意指针类型的子类~
[解决办法]
新标准里面的。用来给指针初始化的。
[解决办法]
[解决办法]
我接受新事物的意愿太低迷了... 无能为力...