微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c – 访问结构中定义的枚举值

如果我有以下内容
struct LineChartScene::LineChartSceneImpl
{
    enum ContextMenuAction {ShowLabels,ShowPoints,SaveAsImage};
};

如何访问LineChartScene :: LineChartSceneImpl结构外的ShowLabels,ShowPoints等?我以为LineChartScene :: LineChartSceneImpl :: ContextMenuAction :: ShowLabels可以工作,但事实并非如此.我正在使用C,Qt Creator 2.2.1.

解决方法

struct LineChartScene::LineChartSceneImpl
{
    enum ContextMenuAction {ShowLabels,SaveAsImage};
};

用它作为

LineChartScene::LineChartSceneImpl::ShowLabels

对于您的信息,C++11 also has strong typed enums具有您期望的命名空间语义:

06002

The scoping of the enumeration is also defined as the enumeration name’s scope. Using the enumerator names requires explicitly scoping. Val1 is undefined,but Enum2::Val1 is defined.

Additionally,C++11 will allow old-style enumerations to provide explicit scoping as well as the deFinition of the underlying type:

06003

The enumerator names are defined in the enumeration’s scope (Enum3::Val1),but for backwards compatibility,enumerator names are also placed in the enclosing scope.

原文地址:https://www.jb51.cc/c/117663.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐