I have a function const void* getData()
which returns a pointer to constant data const void*
I need to write a wrapper to this function that gets an (output) argument in which it should return the above pointer.
void wrapGetData([type] ppData) {
*ppData = getData();
}
What should be the [type]
? void ** is not sutable,since getData() returns pointer to the const
If getData()
returns void const *
, then [type]
should be void const * &
:
void wrapGetData(void const * & ppData)
{
ppData = getData();
}
Note that &
is needed, as ppData
is output parameter.
You can call this function as:
void const * output;
wrapGetData(output);
This is a bit different from the other solution in which you have to call the function as:
wrapGetData(&output); //if [type] = const void **
Note that const void*
and void const*
are same thing. So don't confuse with the syntax.
This is a bit different from the other solution in which you have to call the function as:
wrapGetData(&output); //if [type] = const void **
Hope that helps.
const void**
:
const void *getData() {
return nullptr;
}
void wrapGetData(const void** ppData) {
*ppData = getData();
}
int main() {
const void *p;
wrapGetData(&p);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.