0

Let I have below program. I would like to assign the value to the enum member at run time. How can i do it?

typedef enum test{
    a, b
}test;
typedef struct abc{
    test Test;
}abc;
int main(){

    abc ab;
    ab.Test.a = 5;//Throwing an error as "Expression must have class type"
    return 0;
}

Please help me.

4

3 回答 3

3

为了清楚起见,Anenum只是给 some 命名的一种方式。constants

它很有用,因为与defines相比,您为变量设置的名称(通常)不会被编译器丢弃,因此您可以在使用调试器浏览程序时看到它们。

如果要重新组合变量并为其设置值,请structures改用。

于 2013-03-22T06:50:43.083 回答
3

首先,枚举值是常量,因此以后不能在代码中更改它们。

其次,我不知道你想做什么..

于 2013-03-22T06:48:09.707 回答
1

你的意思是这个吗?

typedef struct test{
    int a, b;
} test;
typedef struct abc{
    test Test;
} abc;

int main(){

    abc ab;
    ab.Test.a = 5;
    return 0;
}
于 2013-03-22T06:54:35.267 回答