我有以下代码:
typedef enum Types{
Type_1, Type_2, Type_3
} MyTypes;
typedef union Tree{
struct {
int MyType;
}structAccessor;
} MyTree;
我正在创建这样的树:
MyTree* node(MyTypes MyType).......//folowwing is unnecessary
我想知道如何找到我的树的类型,如下所示:
if(node->structAccessor.MyType == MyTypes[2]) //if MyType is Type_2, i want to compare this, thanks so much
答案 0 :(得分:0)
enum
始终为int
类型。
您可以针对任何int
if (node->structAccessor.MyType == Type_1)
虽然它们常用于switch
陈述
switch (node->structAccessor.MyType) {
case Type_1:
...
case Type_2:
...
case Type_3:
...
default: // error
}