It seems that nullptr
is declared in the default global namespace. Wouldn't it make sense for it to be in the std
namespace?
2 Answers
nullptr
is a C++11 keyword (no different to if
, public
, true
, void
, etc.), so namespaces don't apply.
-
45
-
1I think he said it just right. The
true
/false
analogy isn't helpful for someone coming from a C background, astrue
/false
in C are just macros defined in stdbool.h which do something like#define true 1
and#define false 0
. So, are you sayingnullptr
is a macro? Is it an integer, like C'strue
/false
? Is it just a zero (0
)?--that would kind of defeat the whole purpose ofnullptr
, now, so that analogy to C++'strue
/false
really really muddles things up. Commented Aug 20, 2020 at 23:38
nullptr
is a pointer literal the same way as for example true
is a boolean literal. This literal has type std::nullptr_t
that is as you see this type is defined in name space std::
The pointer literal is described in section 2.14.7 Pointer literals of the C++ Standard.