繁体   English   中英

:: std :: string和std :: string有什么区别?

[英]What is the difference between ::std::string and std::string?

::std::stringstd::string什么区别前者是全局的? 但全局是什么?不是命名空间std全球? 谢谢你的帮助。

::std::string表示全局命名空间中命名空间std中的string leading ::强制查找在全局命名空间中开始。 因此::std::string总是表示C ++标准库中的string类型。

std::string表示命名空间std string ,其中std将在当前范围中查找。 因此,如果存在名为std的类,名称空间或枚举,则名称查找可能会找到该std

#include <string>
namespace foo {
  namespace std {
    class string { ... };
    namespace bar {
      std::string s;    // means foo::std::string
      ::std::string s;  // means string from standard library
    }
  }
}

只要您和您的合作者同意不指定任何std ,就没有必要使用前导:: 这只是一种很好的风格。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM