I'm having difficulty passing an array of class to an function which needs to operate on members of the classes, what I mean to do the code below should explain.
class Person {
public:
char szName[16];
};
void UpdatePeople(Person* list) //<- this is the problem.
{
for (int i=0;i<10;i++)
{
sprintf(&list[i]->szName, "whatever");
}
}
bool main()
{
Person PeopleList[10];
UpdatePeople(&PeopleList);
return true;
}
You do not need the
&
you can directly pass the arrayIn this call
PeopleList
will decay into aPerson*
Then in your
UpdatePeople
function you can use this asI would, however, recommend using the C++ standard library