c - 二进制表达式 ('struct node ' 和 'struct node ' 的无效操作数)

标签 c struct

我制作了一个头文件,在其中声明了一个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/

相关文章:

c++ - libc 是如何工作的?

c - 如何处理输出结构中的字符串分配

c - 需要有关简单 C 命令行参数的帮助

c++ - operator[] 和 insert() 函数在 C++ 映射中的行为方式不应该相同吗?

c - Printf 未显示并返回值 3221225477

c - 使用 getaddrinfo 将 IPv4 地址转换为 IPv6 地址时丢失服务端口

c - LabVIEW调用库函数生成字符串数组

JSON 字段设置为 null vs 字段不存在

c - 在 C 中修改函数中的变量

c# - 将自定义颜色添加到 Color 结构?