I have a type hierarchy - GenericClass and a number of derived classes, including InterestingDerivedClass, GenericClass - polymorphic. There interface
interface ICallback { virtual void DoStuff( GenericClass* ) = 0; };
which I need to implement. Then I want to determine the case where the GenericClass * pointer passed to ICallback :: DoStuff () is really a pointer to InterestingDerivedClass:
class CallbackImpl : public ICallback { void DoStuff( GenericClass* param ) { if( dynamic_cast<InterestingDerivedClass*>( param ) != 0 ) { return;
GenericClass and derived classes are out of my control, I only manage CallbackImpl.
I timed the dynamic_cast operator - it takes about 1400 cycles, which is acceptable at the moment, but does not look very fast. I tried to read a breakdown of what was done during dynamic_cast in the debugger, and saw that it took a lot of instructions.
Since I really don't need a pointer to a derived class, is there a faster way to determine the type of an object at runtime using only RTTI? Maybe some specific implementation method that checks only the "is" relationship, but does not extract the pointer?
c ++ polymorphism dynamic visual-c ++
sharptooth
source share