How to convert a void pointer to array of classes

Posted by user99545 on Stack Overflow See other posts from Stack Overflow or by user99545
Published on 2012-06-17T03:11:51Z Indexed on 2012/06/17 3:16 UTC
Read the original article Hit count: 105

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c++

Related posts about class