c++ - dynamic_cast of void * -
i need use dynamic cast void*
void *target = (myclass*)target;//i storing initially(to implment delegate mechanism) .... delegateclass *delegate = dynamic_cast<delegateclass*>(target);
it giving error cannot convert void*, cannot use below code... since delegate mechanism
delegateclass *delegate = dynamic_cast<delegateclass*>(((myclass*))target);
how type of target , implement... if use typeid() can name of class how use typeid in above equation instead of (((myclass*))target).
you cannot use dynamic cast unless original type of variable had vtable (ie, had virtual functions). because dynamic_cast requires run-time type information, recorded in vtable; if vtable missing, compiler doesn't know type object is.
you should declare base class virtual destructor, , use pointers base class rather void *
.
Comments
Post a Comment