1

// ポインタで結ばれた 2 つの構造体

 struct A_cust            // customer information, a double-linked list with another pointer
   {
    char cust_info [20];  // as an example
    A_cust *prevCust;     // prev customer record
    A_cust *nextCust;     // next customer record
    B_tran *point_to_B;   // to the list of transaction records
   };

 struct B_tran            // transaction records, a double-linked list with another pointer
   {
    char cust_tran [20];  // as an example
    B_tran *prevTran;     // prev customer transaction
    B_tran *nextCust;     // next customer transaction
    A_cust *point_to_A    // to the list of customer records
   };

コンパイラは、"A_cust" を解析するときに "B_tran" を認識しません。最初に "B_tran" の定義を配置すると、コンパイラは "A_cust" が何であるかを認識しません。

どんなアイデアでも、アーネスト

4

1 に答える 1

3

コードの先頭に次の宣言を追加します

struct B_tran;

編集:これは前方宣言と呼ばれ、後で定義することをコンパイラに約束していますB_tran。(ありがとうグレッグ)

于 2012-06-14T21:18:19.600 に答える