Like this
auto func() {
std::nullptr_t p;
p=nullptr;
return p;
}
I can build this code in msvc, but error in gcc
Like this
auto func() {
std::nullptr_t p;
p=nullptr;
return p;
}
I can build this code in msvc, but error in gcc
std::nullptr_t
is defined in <cstddef>
, to use it you must include that header. That does not imply that your code must fail to compile when you do not include the header.
Due to the way includes work in C++ you often can get away without explicitly including a header, but the commonly accepted rule is that you should include what you use to ensure that your code is portable. Here it is not a transitive include that makes it work, but MSVC decided to have std::nullptr_t
defined without any explicit include. That does not mean that you should not include what you use.
TL;DR: Include headers for what you use to write portable code.