I have three structs, one of which inherits from the other two:
typedef struct _abc
{
int A;
int B;
int C;
} ABC;
typedef struct _def
{
int D;
int E;
int F;
} DEF;
typedef struct _abcdef : ABC, DEF { } ABCDEF;
(I want the third struct to contain all the members of the first two. Is there a better way to do it?)
Now, I have fully populated instances of ABC
and DEF
, and I want to make a new ABCDEF
instance:
int main()
{
ABC abc;
abc.B = 2;
abc.C = 1;
abc.A = 10;
DEF def;
def.D = 32;
def.E = 31;
def.F = 90;
// make a new ABCDEF with all the values of abc and def
}
What is the best way to create the ABCDEF
? I could do this, but it kinda sucks:
ABCDEF abcdef;
abcdef.A = abc.A;
abcdef.B = abc.B;
abcdef.C = abc.C;
abcdef.D = def.D;
abcdef.E = def.E;
abcdef.F = def.F;
The above is coupled to the members of the structs, and is messy if many members are added.