Struct Inheritance in C

后端 未结 12 1642
悲&欢浪女
悲&欢浪女 2020-11-29 00:04

Can I inherit a structure in C? If yes, how?

12条回答
  •  迷失自我
    2020-11-29 00:56

    C has no explicit concept of inheritance, unlike C++. However, you can reuse a structure in another structure:

    typedef struct {
        char name[NAMESIZE];
        char sex;
    } Person;
    
    typedef struct {
        Person person;
        char job[JOBSIZE];
    } Employee;
    
    typedef struct {
        Person person;
        char booktitle[TITLESIZE];
    } LiteraryCharacter;
    

提交回复
热议问题