hoangdangninh
4/13/2017 - 5:51 AM

From http://stackoverflow.com/questions/1237266/how-can-inheritance-be-modelled-using-c

struct parent {
    int  foo;
    char *bar;
};

struct child {
    struct parent base;
    int bar;
};

struct child derived;

derived.bar = 1;
derived.base.foo = 2;

// --------------------------------------------//
// Or even better 
// But if you use MS extension (in GCC use -fms-extensions flag) you can use anonymous nested structs and it will look much better:

struct child {
    struct parent;    // anonymous nested struct
    int bar;
};

struct child derived;

derived.bar = 1;
derived.foo = 2;     // now it is flat