The pointer literal is the keywordAnd this is from 18.2/9:nullptr
. It is a prvalue of typestd::nullptr_t
.
Sonullptr_t
is defined as follows:
namespace std { typedef decltype(nullptr) nullptr_t; }
nullptr
is of type nullptr_t
, and nullptr_t
is defined to be the type of nullptr
.Um, okay.
Scott
5 comments:
Probably so that it doesn't get cast to int, right?
@Tianyu Zhu: I don't know why they defined things the way they did, but there are other ways to define things such that casting to int is not permitted (without a reinterpret_cast).
That's a somewhat consecrated design, also present in Scala and D. "nullptr" is a bottom type in the type lattice just above the "none" type that cannot be instantiated. As such, it has its own interesting properties - most notably it can be instantiated but only with null.
Defining nullptr_t as "the type of nullptr" is a simple solution to avoiding introducing a new keyword for that type.
For me really surprising thing about nullptr is that it is not a pointer, i.e. std::is_pointer<decltype(nullptr)>::value == false. For me it's yet another defect in the C++11.
Post a Comment