问题描述:
引用一个头文件中的结构体,在使用的c文件中,报错: error:unknow type name, 检查了 1.头makefile中的#INCLUDE #VPATH路径都没有问题,2.头文件的写法也没有问题;
具体代码如下:
struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
} ;
代码引用为 Books book1; //报错,error:unknow type name
struct Books book1; //正确
原因是:习惯使用typedef 定义结构体,与上面的结构体定义不同,需要改变引用的方式;不使用typedef的话,需要加个struct。
typedef struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
} Book;
代码引用为 Books book1; //正确