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.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...