给定以下结构,
typedef struct tCard {
CardClass class;
void *proto;
} Card;
typedef struct tCardPath {
PathType path_type;
struct tPath path;
Goal goal;
} CardPath;
是否可以像这样使用宏访问指向 struct (proto) 的指针所指向的元素?
((CardPath*)(trial[i].proto))->element1; // this works
CARD_PROP(trial[i], Path, element1); // the goal
我试过这个,但是error: expected identifier before ‘(’ token
编译时会给出,
#define PROTO(C) (C).proto
#define CARD_PROP(C, CARD, PROP) (((Card##CARD *)(PROTO(C)))->(PROP))
编辑:试过了,还是不行
#define CARD_PROP(C, CARD, PROP) ((Card##CARD *)(PROTO(C))->PROP