gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 18:16:26 26 4
gpt4 key购买 nike

如果我有以下内容:

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

如何在 LineChartScene::LineChartSceneImpl 结构之外访问 ShowLabelsShowPoints 等?我认为 LineChartScene::LineChartSceneImpl::ContextMenuAction::ShowLabels 会起作用,但它不起作用。我正在使用 C++,Qt Creator 2.2.1。

最佳答案

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

用作

LineChartScene::LineChartSceneImpl::ShowLabels

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

enum class Enum2 : unsigned int {Val1, Val2};

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:

enum Enum3 : unsigned long {Val1 = 1, Val2};

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++ - 访问结构中定义的枚举值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8213696/

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