Reputation: 400
So I have my header file listed below. For some reason, when I attempt to compile I get the following errors.
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
I have looked over some other people's similar problems and the responses. I believe they should be defined due to my typedefs. What am I doing wrong?
NOTE: I am not trying to create a pointer to the items, I am trying to use shared memory and have been told to avoid pointers for that purpose. I was thinking about attempting to simply make them all arrays of length 1, but I'm not sure if that is just a round about way to solve the issue, or whether it will actually solve the issue.
Thank you.
#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
Upvotes: 0
Views: 131
Reputation: 121427
When you define the struct objects (like struct myStruct member;
), compiler needs to know the definition of myStruct
in order to allocate storage. You have only typedef's which is just an alias and doesn't tell about the actual structs.
If you re-order the struct defintions to make sure they are visible when others use, you should be fine.
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];
};
Upvotes: 3