带有结构体的未声明标识符

Dou*_*oug 1 c struct undefined-reference

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;
Run Code Online (Sandbox Code Playgroud)

这段代码在 main 之上声明。访问时

report->successfulTransactions
Run Code Online (Sandbox Code Playgroud)

或者

report->failedTransactions
Run Code Online (Sandbox Code Playgroud)

我得到了 FailedTransaction 和SuccessfulTransaction 的未定义标识符。

这是操作报告的代码

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;
}
Run Code Online (Sandbox Code Playgroud)

错误发生在每个 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   
Run Code Online (Sandbox Code Playgroud)

Jon*_*art 7

尝试

sizeof(struct FailedTransaction);
Run Code Online (Sandbox Code Playgroud)

或者,做FailedTransaction一个typedef:

struct _FailedTransaction;
typedef struct  _FailedTransaction FailedTransaction;

struct _FailedTransaction {
    OrderNodePtr order;
    int failureID;
    FailedTransaction* next;
    FailedTransaction* tail;
};
Run Code Online (Sandbox Code Playgroud)

为什么 C 需要“struct”关键字而不是 C++?