c++ - 有没有办法将类嵌入到同名的新命名空间中?

标签 c++ c++11 namespaces typedef facade

我们正试图将一个类隐藏在一个新的命名空间后面,但我们希望保留原来的名称。

namespace first {
    class Logger { ... };
}

namespace second {
    using Logger = first::Logger;
}

error: definition of type 'Logger' conflicts with type alias of the same name class Logger;

最佳答案

是的,我们可以:

namespace first {
  class Logger {  };
}

namespace second {
  typedef first::Logger Logger;
}

typedef is apparently equivalent to using (在 C++11 中),更加实用。

关于c++ - 有没有办法将类嵌入到同名的新命名空间中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35880793/

相关文章:

c++ - 命令 "new"和 "malloc"未正确分配内存

c++ - 用自定义数据类型定义接口(interface):如何保持可读性?

c++ - pimpl 是否与匿名命名空间兼容?

c++ - 对象构造函数 "settings"习语

c++ - constexpr 与模板、pow 函数

c++ - 如何将备忘录应用于此递归函数?

c++ - 试图理解 C++11 中宏、模板和枚举的复杂使用

function - 在 Clojure 中创建一个函数,该函数在其他命名空间中创建 'n' 个 JButton,每个 JButton 具有不同的 'actionPerformed' 方法

c++ - 这个程序的输出怎么会变成 12?

c++ - 模板参数中是否禁止使用 SFINAE,还是我遇到了 clang 错误?