Why isn't 'nullptr' in the 'std' namespace?

邮差的信 提交于 2020-01-03 06:45:10

问题


It seems that nullptr is declared in the default global namespace. Wouldn't it make sense for it to be in the std namespace?


回答1:


nullptr is a C++11 keyword (no different to if, public, true, void, etc.), so namespaces don't apply.




回答2:


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.



来源:https://stackoverflow.com/questions/21510121/why-isnt-nullptr-in-the-std-namespace

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!