【问题标题】:Use enum defined in a struct as case constant in C++使用结构中定义的枚举作为 C++ 中的 case 常量
【发布时间】:2015-02-19 08:06:51
【问题描述】:

我有一个enum 作为头文件中定义的structure 的成员。 例如,

struct abc{
    enum xyz{
        FIRST =1;
        SEC =2;
    }qw;
};

在我的.cpp 文件中,我包含了这个标题。我的文件中有一个switch case,这些enums 将用作case constants

struct abc az;
switch(az.qw){
case FIRST:....
case SEC:...
default:..
}

但我收到FIRST is not declared in this scope 的错误。如何克服这个问题。

【问题讨论】:

  • 你试过abc::FIRST吗?
  • 是的......它工作......谢谢......

标签: c++ struct enums switch-statement


【解决方案1】:

xyz定义在abc的范围内,所以需要

case abc::FIRST:

等等

【讨论】:

  • 天啊!!.. 非常感谢.. 使用 abc::qw::FIRSTabc.qw.FIRSTabc.FIRST 尝试了很多。但没试过这个..谢谢..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-21
  • 2017-04-21
  • 1970-01-01
  • 2022-06-10
  • 2016-11-29
  • 2015-07-06
相关资源
最近更新 更多