问题描述
我无法为C ++中的嵌套结构创建别名。假设下面有这段代码。现在,如何使用BEGIN....END
等为struct Score
创建别名?
typedef
解决方法
如果仅在struct Score
内声明struct Information
,则将无法将其用作自己的实体。所以把它弄出来。
struct Score {
struct Score *link;
float src;
};
struct Information {
struct Score *src;
};
,
在声明typedef
之后仅使用struct Information
。没有理由在结构Information
内定义新类型。
struct Information
{
struct Score
{
struct Score *link;
float src;
} *src;
};
typedef struct Score score;