当我在 C 中编译我的代码时,我收到以下错误“错误 LNK2001:未解析的外部符号_staff”以及有关未解析的外部的错误。听起来它认为我的人员数组需要一个外部文件,但它只是一个用于保存 Persons 的数组(两种类型的联合)。我该如何解决这个问题?我的代码的开头如下。
#include <stdio.h>
#include <string.h>
//employee struct
typedef struct {
//...
} Employee;
//Manager struct inheriting from employee struct
typedef struct {
Employee employee;
int bonus;
} Manager;
//union of manager and employee
typedef union{
Employee e;
Manager m;
} Person;
//functions
Employee newEmployee(char n[], ...);
Manager newManager(...);
double getManagerSalary(Manager man);
Manager boss;
Employee harry ;
Employee tommy;
Person staff[];
//main code
int main(void)
{
boss = newManager(...);
harry = newEmployee(...);
tommy = newEmployee(...);
staff[3];
staff[0].m = boss;
staff[1].e = harry;
staff[2].e = tommy;
...
}
Employee newEmployee(char n[], double s, int year, int month, int day)
{
...
}