【发布时间】:2012-11-18 00:58:52
【问题描述】:
所以,出乎意料的是,编译器决定当面吐槽: “现场客户的类型不完整”。
以下是相关的sn-ps代码:
customer.c
#include <stdlib.h>
#include <string.h>
#include "customer.h"
struct CustomerStruct;
typedef struct CustomerStruct
{
char id[8];
char name[30];
char surname[30];
char address[100];
} Customer ;
/* Functions that deal with this struct here */
客户.h
customer.h 的头文件
#include <stdlib.h>
#include <string.h>
#ifndef CUSTOMER_H
#define CUSTOMER_H
typedef struct CustomerStruct Customer;
/* Function prototypes here */
#endif
这是我的问题所在:
customer_list.c
#include <stdlib.h>
#include <string.h>
#include "customer.h"
#include "customer_list.h"
#include "..\utils\utils.h"
struct CustomerNodeStruct;
typedef struct CustomerNodeStruct
{
Customer customer; /* Error Here*/
struct CustomerNodeStruct *next;
}CustomerNode;
struct CustomerListStruct;
typedef struct CustomerListStruct
{
CustomerNode *first;
CustomerNode *last;
}CustomerList;
/* Functions that deal with the CustomerList struct here */
这个源文件有一个头文件 customer_list.h ,但我认为它不相关。
我的问题
在 customer_list.c 中,在带有注释 /* Error Here */ 的行中,编译器抱怨 field customer has incomplete type.
我整天都在谷歌上搜索这个问题,现在我要拔出我的眼球并将它们与草莓混合。
这个错误的根源是什么?
提前致谢:)
[附注如果我忘了提什么,请告诉我。正如你所言,这对我来说是压力很大的一天]
【问题讨论】:
-
结构定义本身必须在标头中,而不仅仅是 typedef。
-
编译器需要知道
struct,因为它需要知道每个数据的大小。 -
首先出现在我面前的是
"..\utils\utils.h",但我怀疑这会导致错误。不过,tils不是十六进制数字。 -
让我猜猜...如果您更改包含
customer.h和customer_list.h的顺序,一切都会开始工作。你应该在使用它之前定义你的结构! -
这只是我编写的源文件的标题,具有我在整个项目中使用的常用功能。删除重复代码:)
标签: c struct typedef header-files incomplete-type