Array of struct as function parameter
How to pass an array of struct as a function parameter?
This is not working:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
struct Person
{
char* name;
int age;
Person(char* name, int age)
{
this->name = name;
this->age = age;
}
};
struct XYZ
{
int count;
Person* people[];
XYZ(int count, Person* people[])
{
this->count = count;
this->people = people; // << Error here.
}
};
void ABC()
{
Person* people[] = { new Person("Tom", 18), new Person("Jacob", 25) };
// Error can't convert from people[2] to people[]
XYZ* xyz = new XYZ(2, people);
}
|
Thanks
Last edited on
Person* people[]
Is an incomplete type as the actual size is unspecified.
You need to use Person** people
, except where the size is know, i.e. the declaration.
Thanks. Solved my problem.
Topic archived. No new replies allowed.