2012-06-14 17 views
1

// 2結構通過指針綁鏈表依賴於其他的B是關係回到A

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 
    }; 

編譯器不知道「B_tran」,當它解析「A_cust」 如果我把定義「B_tran」的第一則編譯器根本不知道什麼是「A_cust」是

任何想法,歐內斯特

回答

3

在你的代碼的頂部添加以下聲明

struct B_tran; 

編輯:這被稱爲前向聲明,你很有希望編譯器,你會在後面定義B_tran。 (感謝格雷格)

+2

這就是所謂的向前聲明。 – gcochard