J
jim.deveraux
I have this bizarro argument in a function that's been written for me
that I can't figure out. The abstracted function looks like:
void DoSomething(void *&arg)
I think the argument is a void pointer to a pass by reference. But I
can't seem to get it to work. The DoSomething function uses arg to
return a pointer to a dynamically allocated struct.
void DoSomething(void *&arg)
{
myStruct * tmp = new myStruct;
tmp->myParameter = 555;
arg = tmp;
}
Back at the code where I called DoSomething however, I can't seem to
dereference the void pointer correctly and get at the parameters
inside. How do you do it? I tried
void *tmp;
DoSomething((void *) tmp);
(myStruct *) tmp->myParameter;
But no dice. I get error:
error C2227: left of '->myParameter' must point to class/struct/union
Any suggestions? Most of my problem is I don't know how to interpret or
use correctly a void *&arg data type, and can not find resources that
would properly explain it. Also, this implementation is not mine and I
cannot change it to another, simpler format of data type.
that I can't figure out. The abstracted function looks like:
void DoSomething(void *&arg)
I think the argument is a void pointer to a pass by reference. But I
can't seem to get it to work. The DoSomething function uses arg to
return a pointer to a dynamically allocated struct.
void DoSomething(void *&arg)
{
myStruct * tmp = new myStruct;
tmp->myParameter = 555;
arg = tmp;
}
Back at the code where I called DoSomething however, I can't seem to
dereference the void pointer correctly and get at the parameters
inside. How do you do it? I tried
void *tmp;
DoSomething((void *) tmp);
(myStruct *) tmp->myParameter;
But no dice. I get error:
error C2227: left of '->myParameter' must point to class/struct/union
Any suggestions? Most of my problem is I don't know how to interpret or
use correctly a void *&arg data type, and can not find resources that
would properly explain it. Also, this implementation is not mine and I
cannot change it to another, simpler format of data type.