gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:32:06 27 4
gpt4 key购买 nike

我有一个包含枚举的类:

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com