How to convert a void pointer to array of classes
- by user99545
I am trying to convert a void pointer to an array of classes in a callback function that only supports a void pointer as a means of passing paramaters to the callback.
class person
{
std::string name, age;
};
void callback (void *val)
{
for (int i = 0; i < 9; i++)
{
std::cout << (person [])val[i].name;
}
}
int main()
{
person p[10];
callback((void*)p);
}
My goal is to be able to pass an array of the class person to the callback which then prints out the data such as their name and age. However, the compile does not like what I am doing and complains that error: request for member 'name' in 'val', which is of non-class type 'void*' How can I go about doing this?