2 種類の C 構造体を格納するための 1 つの配列を作成したいと思います -Employee
とその「子」です Manager
。それらのいずれかを保持するユニオンを作成Person
し、それを使用して配列を作成しようとしましたが、機能しません。このような配列を機能させるにはどうすればよいですか? 関連するコードは以下です。
typedef struct {
char name[20];
double salary;
} Employee;
//Manager struct inheriting from employee struct
typedef struct {
Employee employee;
int bonus;
} Manager;
typedef union{
Employee e;
Manager m;
} Person;
Manager boss;
Employee harry ;
Employee tommy;
Person staff[];
int main(void)
{
...
boss = newManager(...);
harry = newEmployee(...);
tommy = newEmployee(...);
次の行が機能しませんでした。多くのことを試しました。
staff[3] = {boss, harry, tommy};