C Typedef - 不完整的类型 [英] C Typedef - Incomplete Type

查看:42
本文介绍了C Typedef - 不完整的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,出乎意料地,编译器决定把这个吐出来:现场客户的类型不完整".

So, out of the blue, the compiler decides to spit this in face: "field customer has incomplete type".

以下是相关代码片段:

#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 的头文件

customer.h

A header file for customer.h

#include <stdlib.h>
#include <string.h>

#ifndef CUSTOMER_H
#define CUSTOMER_H

    typedef struct CustomerStruct Customer;

    /* Function prototypes here */

#endif

这就是我的问题所在:

#include <stdlib.h>
#include <string.h>

#include "customer.h"
#include "customer_list.h"

#include "..utilsutils.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 ,但我认为它不相关.

This source file has a header file, customer_list.h ,but I don't think its relevant.

在customer_list.c中,在注释/* Error Here */的那一行,编译器抱怨field customer has不完整的类型.

In customer_list.c, at the line with the comment /* Error Here */, the compiler complains about field customer has incomplete type.

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

I've been googling this problem all day, and now im at the point of pulling out my eyeballs and blending them with strawberries.

这个错误的根源是什么?

What is the source of this error ?

提前致谢:)

[附注如果我忘记提及某事,请告诉我.正如你可能会说的,这对我来说是充满压力的一天]

[P.S. if I forgot to mention something, let me know. Its been a stressful day for me, as you might tell ]

推荐答案

将 struct 声明移至标题:

Move the struct declaration to the header:

customer.h
typedef struct CustomerStruct
{
...
}

这篇关于C Typedef - 不完整的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆