I am using Tcl_CreateObjCommand(interp, cmdName, proc, clientData, deleteProc) in my code and passing in a DerivedClass pointer to the clientData parameter. In the callback function, I want to type safe convert (dynamic_cast) the clientData back to the DerivedClass pointer, but the gcc compiler is complaining "source is not a class to pointer
". This is because the clientData is a type of void pointer. In this use case, how would developers usually handle this issue when using Tcl API?
int main()
{
...
Tcl_CreateObjCommand(interp, cmdName, myCallback, myDerivedClassPointer, (Tcl_CmdDeleteProc *)NULL);
}
myCallback(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj* const objv[])
{
// I want to do something like this, so when the pointer is not a DerivedClassPointer type, throw an exception.
DerivedClass* foo = dynamic_cast<DerivedClass*>(clientData);
if(!foo) throw exception, type conversion fail
}