Typedef struct指向另一个typedef结构的指针

时间:2014-11-28 20:26:05

标签: c struct

我对此代码有一些问题:

typedef struct Product {

    char product_code[5];
    int sells;
    int sells_quantity;
}p[3];

typedef struct Seller {
    char seller_code[5];
    Product *ptr;
}seller[5];

为什么Product *ptr给我一个错误?

2 个答案:

答案 0 :(得分:1)

您可以尝试替换代码吗

typedef struct Product {

    char product_code[5];
    int sells;
    int sells_quantity;
}p[3];

typedef struct Product {

    char product_code[5];
    int sells;
    int sells_quantity;
} Product;               // from here the structure type Product is recognized by the compiler. 

答案 1 :(得分:0)

你可以这样做:

typedef struct Product {

char product_code[5];
int sells;
int sells_quantity;
}p[3],Product;

typedef struct Seller {
  char seller_code[5];
  Product *ptr;
}seller[5];