c++ - 是否需要 nullptr_t 类型的对象?

标签 c++ c++11 nullptr

引用 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: Although nullptr’s address cannot be taken, the address of another nullptr_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/

相关文章:

c++ - 使用继承的 luabind 和 std::shared_ptr

c++ - 为什么不通过文件读取简单字符?

c++ - 忽略注释 : offset of packed bit-field without using "-Wno-packed-bitfield-compat"

c++ - 在使用 C++ 的简单文本 RPG 游戏中,变量的值没有改变

c++ - 使用静态初始化来注册类

c++ - C++17 标准对 nullptr 调用 delete 有何规定?

c++ - nullptr和 bool 值之间的比较

c++ - 如何将 nullptr 作为参数传递?

c++ - 使用透明 std 函数对象时,我们还需要写空尖括号吗?

c++ - 如何设置默认g++?