gpt4 book ai didi

C Typedef - 不完整的类型

转载 作者:太空狗 更新时间:2023-10-29 17:05:13 24 4
gpt4 key购买 nike

所以,出乎意料的是,编译器决定当面吐槽:“现场客户的类型不完整”。

下面是相关的代码片段:

客户.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

这是我的问题所在:

客户列表.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。

我一整天都在谷歌搜索这个问题,现在我正要挖出我的眼球并将它们与草莓混合。

此错误的来源是什么?

提前致谢:)

[附言如果我忘记提及某事,请告诉我。正如你所说,这对我来说是压力很大的一天]

最佳答案

将结构声明移至 header :

customer.h
typedef struct CustomerStruct
{
...
}

关于C Typedef - 不完整的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13634495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com