2012-06-14 14 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