c++ - 导出类的部分命名空间

标签 c++ enums namespaces using-statement

我有一个包含枚举的类:

class appearance{
  // ... stuff ...
  enum color {BLUE, RED, GREEN};
};

我想附加命名空间的一部分(使用 using),这样我就可以将 BLUE 的值简单地称为 BLUE,而不是 appearance::BLUE。同时,我想将 enum 保留在 class{} 中,因为我认为这是最自然的做法。我尝试了 namespaceusing 的各种组合,但都无济于事。

有什么建议吗???

最佳答案

我认为这是不可能的。 AFAIK,您可以按照规定在另一个类或结构中使用 using appearance::color here .

A using declaration in a class A may name one of the following:

  • A member of a base class of A

  • A member of an anonymous union that is a member of a base class of A

  • An enumerator for an enumeration type that is a member of a base class of A

关于c++ - 导出类的部分命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3925244/

相关文章:

java - 在数组上存储 Piece 对象 - java Tetris Tutorial

xml - 为什么要限定实例文档中的全局元素?

c++ - 命名空间中的无效数据类型转换

c++ - 评估潜在常量表达式期间的未定义行为

c++ - 没有可用于带有初始值设定项的静态常量成员的定义?

javascript - 如何在React中通过数字键从枚举中获取值

ios - 枚举大小写的原始值必须是字符串的文字错误

c# - 从非托管代码 : SAFEARRAY 调用托管 COM

c++ - 写入 .ini 文件 - SimpleIni SetValue 没有做任何事情,尽管看起来成功了

xml - Xslt 更改节点并添加命名空间