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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/c/117663.html

猜你在找的C&C++相关文章