[英]Initializing a structure in C gives “declaration of anonymous struct must be a definition” error
I declare a structure in my C code known as an edge 我在C代码中声明了一个称为边缘的结构
struct edge{
int weight;
struct node *Node1;
struct node *Node2;
};
where node is another structure that is defined in my code as well. 其中的节点也是我的代码中定义的另一种结构。 When I attempt to declare an edge in my code I use 当我尝试在代码中声明边时,我使用
struct edge *ab=(struct edge*)malloc(sizeof(struct(edge));
This gives me two errors: 1)declaration of anonymous struct must be a definition 2)type name requires a specifier or qualifier. 这给了我两个错误:1)匿名结构的声明必须是定义2)类型名称需要指定符或限定符。
What am I doing incorrectly? 我做错了什么? For further reference my node structure is defined as 为了进一步参考,我的节点结构定义为
struct node{
char data;
struct node *parent;
} ;
sizeof(struct(edge))
must be 一定是
sizeof(struct edge)
Adding ()
to a structure tag is not allowed. 不允许在结构标记中添加()
。
Update this statement 更新此声明
struct edge *ab=(struct edge*)malloc(sizeof(struct(edge));
the following way 以下方式
struct edge *ab = ( struct edge* )malloc( sizeof(struct edge ) );
You have a redundant open parenthesis in the original statement. 您在原始语句中有一个多余的右括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.