I have a function that I need to call
开发者_如何学运维int (*trytoprint_f)(int val, void *param);
but when I call this function, and put
str name = {"jack", 4};
int age = 2;
client->trytoprint(age, (void *)name));
it gives me an error of "cannot convert to a pointer type : C error"
I know the solution which is basically use a function below str_dup_ptr(name, ulr->imsi, mem); and it works (I got this function from a framework).
Anyways, I am just confused. So the question is if the function accepts (void *param), and I declare name variable with type str, howso when I cast this "name" variable into void pointer, it returns me this error?
Can anyone help me in understanding why this error happens?
Thank you
You have to convert a pointer to structure to void* not a structure itself. Try this way
client->trytoprint(age, (void *) &name));
精彩评论