0

我有以下代码:

people[nextfreeplace] -> personName = name;
people[nextfreeplace] -> age = age;

typedef struct person
{
  char *personName;
  int age;
}Person;

人声明是Person *people[]

我收到一个error: request for member 'personName' in something not a structure or union

error: request for member 'age' in something not a structure or union

但我不确定程序有什么问题。

谢谢

4

3 回答 3

2

我假设peoplePerson *or Person[]

使用 operator->时,您可以取消引用并访问该变量。相当于做(*var).personName

用点更改->,就像使用 person[1] 时一样,您已经取消引用您的指针,然后像使用简单的操作一样访问您的变量Person var

people[nextfreeplace].personName = name;
people[nextfreeplace].age = age;
于 2012-10-25T09:28:52.677 回答
0

使用.而不是->因为您使用的是结构数组。

于 2012-10-25T09:25:18.560 回答
0

类型的声明需要在访问类型的(成员)实例之前完成。

typedef struct person
{
  char *personName;
  int age;
}Person;

...

Person *people[];

...

people[nextfreeplace] -> personName = name;
people[nextfreeplace] -> age = age;
于 2012-10-25T09:43:30.913 回答