C : typedef struct name {…}; VS typedef struct{…} name;

后端 未结 6 755
陌清茗
陌清茗 2020-11-29 15:59

As the title says, I have this code:

    typedef struct Book{
        int id;
        char title[256];
        char summ         


        
6条回答
  •  失恋的感觉
    2020-11-29 16:41

    The other answers are all correct and useful, but maybe longer that necessary. Do this:

    typedef struct Book Book;
    typedef struct Books Books;
    typedef struct Author Author;
    
    struct Book {
        ... as you wish ...
    };
    
    struct Author {
        ... as you wish ...
    };
    
    struct Books {
        ... as you wish ...
    };
    

    You can define the your struct's in any order provided they only contain pointers to other struct's.

提交回复
热议问题