【发布时间】:2013-04-16 06:26:01
【问题描述】:
当我尝试编译下面的程序时,我收到错误,因为请求成员“机器”不是结构或联合
struct machine
{
int a;
int b;
int c;
};
struct config
{
struct machine *machine;
int n;
};
int main()
{
struct config *conf;
struct machine *mach;
mach->a=1;
mach->b=2;
mach->c=3;
conf.machine=mach; /* error in this line */
return 0;
}
谁能帮我修复这个错误..提前谢谢!!!
【问题讨论】:
-
使用
struct config *conf;,您只需定义来自config conf类型的指针,但您必须为其分配内存。struct machine也是如此。使用 malloc。