I have a function that returns a const void* and I'd like to use its information as a char*. I can cast it C-style fine as (char *)variable but when I try to use reinterpret_cast like reinterpret_cast<char *>(variable), I get a compilation error.
Should I use a different casting method?
const void *p;
void *q = const_cast<void *>(p);
char *r = static_cast<char *>(q);
The first cast gets rid of const and yields a void *
The second cast changes the data type and yields a char *
Read about the different C++ casts here
Either reinterpret_cast<const char*>(variable) or, if you really are absolutely sure you can ignore the const qualifier, const_cast<char*>(reinterpret_cast<const char*>(variable)).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With