引用 C++11:(18.2/9)
nullptr_t
is defined as follows:namespace std { typedef decltype(nullptr) nullptr_t; }
The type for which
nullptr_t
is a synonym has the characteristics described in 3.9.1 and 4.10. [ Note: Althoughnullptr
’s address cannot be taken, the address of anothernullptr_t
object that is an lvalue can be taken. —end note ]
我们是否需要类型为 nullptr_t
的对象(nullptr
除外)?
最佳答案
nullptr
是一个纯右值,所以你不能获取它的地址。 (它不是对象。)注释指的是这样的情况:
nullptr_t n;
然后,n
是类型为 nullptr_t
的普通对象,因此您可以获取它的地址。这似乎没有任何用处,但在通用代码中,这个特性可能会以某种方式出现。
关于c++ - 是否需要 nullptr_t 类型的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57593245/