为什么'nullptr'不在'std'命名空间中?

时间:2022-12-27 21:13:20

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

似乎nullptr是在默认的全局名称空间中声明的。它在std命名空间中不是很有意义吗?

2 个解决方案

#1


71  

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

nullptr是一个c++ 11关键字(与if、public、true、void等没有区别),因此不应用名称空间。

#2


27  

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.

nullptr是一个指针文字,就像true是一个布尔文字一样。该文字具有std::nullptr_t类型,如您所见,该类型在名称空间std:::中定义。

#1


71  

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

nullptr是一个c++ 11关键字(与if、public、true、void等没有区别),因此不应用名称空间。

#2


27  

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.

nullptr是一个指针文字,就像true是一个布尔文字一样。该文字具有std::nullptr_t类型,如您所见,该类型在名称空间std:::中定义。