gpt4 book ai didi

c - 编译时类型不完整,类型已经定义

转载 作者:太空宇宙 更新时间:2023-11-04 07:23:18 24 4
gpt4 key购买 nike

下面列出了我的头文件。出于某种原因,当我尝试编译时出现以下错误。

orders.h:39: error: field ‘category_transactions’ has incomplete type
orders.h:51: error: field ‘address’ has incomplete type
orders.h:52: error: field ‘successful_trans’ has incomplete type
orders.h:53: error: field ‘failed_trans’ has incomplete type

我查看了一些其他人的类似问题和响应。我相信由于我的类型定义,它们应该被定义。我究竟做错了什么?

注意:我并不是要创建一个指向项目的指针,我是在尝试使用共享内存并且被告知要避免为此目的使用指针。我正在考虑尝试简单地使它们成为长度为 1 的所有数组,但我不确定这是否只是解决问题的一种方式,或者它是否真的能解决问题。

谢谢。

#ifndef ORDERS_H
#define ORDERS_H

#define MAX_TRANS 30
#define MAX_CATEGORY 4
#define MAX_CUSTOMERS 30
#define MAX_CUSTOMER_ID 30
#define MAX_CUSTOMER_NAME 50
#define MAX_ITEM_NAME 100
#define MAX_CATEGORY_NAME 30
#define MAX_ZIP 10
#define MAX_STATE 20
#define MAX_STREET_CITY 80
#define SEM_ORDER_LIST "/order@@list"
#define SEM_USER_DATABASE "/user@@db"
#define SEM_PENDING_LIST "/pend@@list"

typedef struct Transaction Transaction;
typedef struct Item Item;
typedef struct Customer Customer;
typedef struct Mailing_Address Mailing_Address;
typedef struct Category Category;
typedef struct Category_List Category_List;
typedef struct Customer_List Customer_List;
typedef struct Transaction_List Transaction_List;



struct Category{
char category_name[MAX_CATEGORY_NAME];
Transaction_List category_transactions;
};

struct Category_List{
unsigned int curr_length;
Category all_categories[MAX_CATEGORY];
};

struct Customer{
char customer_name[MAX_CUSTOMER_NAME];
char customer_id[MAX_CUSTOMER_ID];
double credit_balance;
Mailing_Address address;
Transaction_List successful_trans;
Transaction_List failed_trans;
};

struct Customer_List{
unsigned int curr_length;
Customer all_customers[MAX_CUSTOMERS];
};

struct Item{
char item_name[MAX_ITEM_NAME];
double price;
char category_name[MAX_CATEGORY_NAME];
};

struct Mailing_Address{
char zipcode[MAX_ZIP];
char state[MAX_STATE];
char street_city[MAX_STREET_CITY];
};

struct Transaction{
Item object;
char customer_id[MAX_CUSTOMER_ID];
};

struct Transaction_List{
unsigned int curr_length;
Transaction all_transactions[MAX_TRANS];
};

#endif

最佳答案

当您定义结构对象(如struct myStruct 成员;)时,编译器需要知道myStruct 的定义以便分配存储。您只有 typedef,它只是一个别名,并没有说明实际的结构。

如果您重新排序结构定义以确保它们在其他人使用时可见,您应该没问题。

 typedef struct Transaction Transaction; 
typedef struct Item Item;
typedef struct Customer Customer;
typedef struct Mailing_Address Mailing_Address;
typedef struct Category Category;
typedef struct Category_List Category_List;
typedef struct Customer_List Customer_List;
typedef struct Transaction_List Transaction_List;

struct Mailing_Address{
char zipcode[MAX_ZIP];
char state[MAX_STATE];
char street_city[MAX_STREET_CITY];
};

struct Item{
char item_name[MAX_ITEM_NAME];
double price;
char category_name[MAX_CATEGORY_NAME];
};


struct Transaction{
Item object;
char customer_id[MAX_CUSTOMER_ID];
};

struct Transaction_List{
unsigned int curr_length;
Transaction all_transactions[MAX_TRANS];
};


struct Category{
char category_name[MAX_CATEGORY_NAME];
Transaction_List category_transactions;
};

struct Category_List{
unsigned int curr_length;
Category all_categories[MAX_CATEGORY];
};

struct Customer{
char customer_name[MAX_CUSTOMER_NAME];
char customer_id[MAX_CUSTOMER_ID];
double credit_balance;
Mailing_Address address;
Transaction_List successful_trans;
Transaction_List failed_trans;
};

struct Customer_List{
unsigned int curr_length;
Customer all_customers[MAX_CUSTOMERS];
};

关于c - 编译时类型不完整,类型已经定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20091172/

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