简体   繁体   English

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

[英]Typedef struct pointer to another typedef struct

I have some problems with this code: 我的代码有一些问题:

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

Why does it give me an error for Product *ptr ? 为什么给我Product *ptr一个错误?

Could you try replace your code 您可以尝试替换您的代码吗

typedef struct Product {

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

With

typedef struct Product {

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

You can do this : 你可以这样做 :

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM