I have the following union:
union employee
{
char key;
struct manager
{
short int age;
float shares;
short int level;
};
struct worker
{
short int age;
short int skill;
short int department;
};
} company[10];
How can I access a member of a structure which is inside the union employee?
I tried to access the age member of the manager structure this way:
company[i].manager.age
But I get error C2039: 'manager' : is not a member of 'employee'.
Add something after the tag declaration. Perhaps:
Side note: you’re not using the union right. The key, i.e. the field that tells you whether you are dealing with a manager or with a mere worker should be in an enclosing object, outside the union. Perhaps:
As dasblinkenlight notes, you could declare your manager / worker tags outside the union.