【问题标题】:Is there a way to call a class in a global namespace?有没有办法在全局命名空间中调用一个类?
【发布时间】:2016-06-01 18:54:53
【问题描述】:

我很难说出这个问题,但这是我的代码开始:

namespace UserInterface
{
   class UiClass
   {
   };
}

namespace Project
{
   namespace UserInterface
   {

   }
}


namespace Project
{
   UserInterface::UiClass uiClass;
}

所以该代码将无法工作,因为 UserInterface 是一个全局命名空间,但它也在 Project 内部,所以当我在 Project 内部实例化 UiClass 时,它会尝试查看内部 Project->UserInterface 而不仅仅是 @987654327 @。是否有某种方法可以具体说明我想使用全局 UserInterface 而不是内部 Project 或者我需要更改我的设计?

【问题讨论】:

    标签: c++ c++11 namespaces


    【解决方案1】:

    您可以使用前导 :: 强制名称查找从全局范围开始。

    ::UserInterface::UiClass uiClass;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      • 2021-05-10
      • 2016-06-23
      • 2020-02-23
      • 1970-01-01
      相关资源
      最近更新 更多