Re: storing related structs





Army1987 wrote:
"Grey Alien" <grey@xxxxxxxxxxxxx> ha scritto nel messaggio news:Z7OdnWRcAeZVoxvbnZ2dnUVZ8vidnZ2d@xxxxxxxxx

<snip>
</snip>
Is there a soln to this problem ?

struct C {
unsigned id;
char name; /* do you mean *name, or name[LARGE_ENOUGH]? */
enum { strA, strB } type;
union {
struct A str_A;
struct B str_B;
} the_struct;
};

A union is like a struct, but can only hold an element at a time.
You access members of unions like members of struct. For example,
in the case above to access the double of a struct B in a struct C,
you'll have to use mystructC.the_struct.str_B.z
Or try to find a better way to do what you're trying to do.


Thanks - I forgot about unions ! (don't use them that much). Yes this soln will suffice for what I want to do.
.



Relevant Pages