C++ 如何使用结构在类中导航switch语句?

C++ 如何使用结构在类中导航switch语句?,c++,class,struct,switch-statement,C++,Class,Struct,Switch Statement,如何使用struct在类成员函数中导航switch语句 我有一个结构,它包含我想在switch语句中使用的数据(uint8\u t、unit16\u t、int16\u t等)。当我试图在另一个需要读取此数据的类中实现它时,我最初在一个临时文件中原型化的内容不起作用 这是我的C++代码的一个通用版本: struct toSwitch{ const int one = 1; const int two = 2; }; struct toSwitch{ const int

如何使用struct在类成员函数中导航switch语句

我有一个结构,它包含我想在switch语句中使用的数据(uint8\u t、unit16\u t、int16\u t等)。当我试图在另一个需要读取此数据的类中实现它时,我最初在一个临时文件中原型化的内容不起作用

这是我的C++代码的一个通用版本:

struct toSwitch{
    const int one = 1;
    const int two = 2;
};

struct toSwitch{
    const int one = 1;
    const int two = 2;
};

class testClass{
public:
    void foo(){
        switch (temp) {
        case tosB.one:
            cout << "ONE" << endl;
            break;
        case tosB.two:
            cout << "TWO" << endl;
            break;
        default:
            break;
        }
    }
private:
    toSwitch tosB;
    int temp = 1;
};

int main()
{
    constexpr toSwitch tosA;
    int swTest= 1;

    switch (swTest) {
    case tosA.one:
        cout << "ONE" << endl;
        break;
    case tosA.two:
        cout << "TWO" << endl;
        break;
    default:
        break;
    }

    testClass b;
    b.foo();

    return 0;
}
struct-toSwitch{
常数int one=1;
常数int 2=2;
};
结构转换开关{
常数int one=1;
常数int 2=2;
};
类testClass{
公众:
void foo(){
开关(温度){
案例一:

CUT在代码> ToSwitter 定义中,使其为代码>静态const int=1;<代码> >静态conExpRint 1=1;。然后在<代码>开关<代码>语句中,<代码> >代码>枚举,如
enum类toSwitch{one=1,two=2};
使用的方法与
case-toSwitch::one: