【发布时间】:2013-11-25 00:12:24
【问题描述】:
struct FailedTransaction{
OrderNodePtr order;
int failureID;
struct FailedTransaction* next;
struct FailedTransaction* tail;
};
typedef struct FailedTransaction* FailedTransactionPtr;
struct SuccessfulTransaction{
OrderNodePtr order;
struct SuccessfulTransaction* next;
struct SuccessfulTransaction* tail;
};
typedef struct SuccessfulTransaction* SuccessfulTransactionPtr;
struct FinalReport{
FailedTransactionPtr failedTransactions;
SuccessfulTransactionPtr successfulTransactions;
};
struct FinalReport* report = NULL;
这段代码在 main 上面声明。访问时
report->successfulTransactions
或
report->failedTransactions
我得到 FailedTransaction 和 SuccessTransaction 的未声明标识符。
这是操作报告的代码
if(report == NULL){
report = malloc(sizeof(struct FinalReport));
report->failedTransactions = NULL;
report->successfulTransactions = NULL;
}
if(outcome){
if(report->successfulTransactions == NULL){
report->successfulTransactions = malloc(sizeof(SuccessfulTransaction));
report->successfulTransactions->order = temp;
report->successfulTransactions->tail = report->successfulTransactions;
}else{
report->successfulTransactions->tail->next = malloc(sizeof(SuccessfulTransaction));
report->successfulTransactions->tail->next->order = temp;
report->successfulTransactions->tail = report->successfulTransactions->tail->next;
}
}else{
if(report->failedTransactions == NULL){
report->failedTransactions = malloc(sizeof(FailedTransaction));
report->failedTransactions->order = temp;
report->failedTransactions->tail = report->failedTransactions;
}else{
report->failedTransactions->tail->next = malloc(sizeof(FailedTransaction));
report->failedTransactions->tail->next->order = temp;
report->failedTransactions->tail = report->failedTransactions->tail->next;
}
report->failedTransactions->failureID = outcome;
}
错误发生在每个 if 语句和 else 语句之后的第一行。
这是一个任务,我已经坚持了一个小时左右(明天晚上到期)。无法弄清楚为什么会这样,我在网上找不到任何东西。任何帮助将不胜感激。
这是包含 OrderNodePtr 的头文件
#ifndef _CONSUMER_
#define _CONSUMER_
struct OrderNode{
char title[250];
int id;
double cost;
char category[250];
struct OrderNode* next;
struct OrderNode* tail;
};
typedef struct OrderNode* OrderNodePtr;
#endif
【问题讨论】:
-
不认为我需要添加它,但既然你问我会的。
标签: c struct undefined-reference