如果我有以下内容:
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,butEnum2::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.