我制作了一个头文件,在其中声明了一个struct node
并制作了一个对象作为该结构的List
。
这是我的头文件 link.h:
struct node
{
void *data; //Generic data
struct node *next;
}List;
Driver.c:
#include "link.h"
int main()
{
List list1;
return 0;
}
当我尝试写这样的语句时
List list1; //in the driver file
它抛出一个错误说:
invalid operands to binary expression ('struct node' and 'struct node')
use of undeclared identifier 'list1'; did you mean 'List'?
这可能是什么原因造成的?
最佳答案
很可能你的意图是让 List
成为 struct node
的别名,所以你需要使用 typedef
,否则 List
不是类型,而是结构的实例变量。
typedef struct node
{
void *data; //Generic data
struct node *next;
}List;
关于c - 二进制表达式 ('struct node ' 和 'struct node ' 的无效操作数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38466854/