我在这个实现中遇到了很多错误。
typedef struct EmployeeStruct
{
char lastName[MAX_LENGTH];
char firstName[MAX_LENGTH];
int employeeNumber; // Holds the employee's ID. This value is
// equal to the number of employees
struct EmployeeStruct *Next; // Pointer to the next most recently hired Employee
}Employee;
当试图创建一个将返回指向该结构的指针的函数时,问题就出现了。错误出现在 malloc 调用中,并导致“new”未正确声明,因此此函数中的所有行都有错误。
Employee* hireEmployee(Employee tail, char lastName[MAX_LENGTH], char firstName[MAX_LENGTH])
{
struct Employee *new = (Employee*)malloc(sizeof(Employee));
new.lastName = lastName;
new.firstName = firstName;
new.next = tail;
tail.next = new;
new.employeeNumber = employeeCount;
return tail;
}
这是错误列表。谢谢您的帮助!
lab6.c:19: warning: initialization from incompatible pointer type
lab6.c:20: error: request for member ‘lastName’ in something not a structure or union
lab6.c:21: error: request for member ‘firstName’ in something not a structure or union
lab6.c:22: error: request for member ‘next’ in something not a structure or union
lab6.c:23: error: ‘Employee’ has no member named ‘next’
lab6.c:24: error: request for member ‘employeeNumber’ in something not a structure or union
lab6.c:26: error: incompatible types in return