I have function declaration as below
void func1(const void& * pThis) {
MyClass* pMyClass = static_cast<MyClass*>(pThis); //....I use PMyClass pointer.
}
I am getting error cannot convert const void*
to MyClass*
How to do this step?
You can
MyClass* pMyClass = const_cast<MyClass*>( static_cast<const MyClass*>(pThis) );
But this awful syntax is the hint: why then the function has a const argument, wouldn't you want it to be like
void func1(void * pThis) {
Of course, you can take a shortcut using C-style cast:
MyClass* pMyClass = (MyClass*)pThis;
but I would fix the design instead if possible.
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