I have a circumstance where multiple inheritance is required. I have a class layout something like the following.
Now, I need to use GetMode() to access the mode but I need to cast it to SpecialModeCommon in order to access some of the special methods/objects. At the point where I am doing this I can be sure that the Mode is also of type SpecialModeCommon.Code:class Mode { } class ModeType1 : Mode { } class ModeType2 : Mode { } class SpecialModeCommon { } class SpecialModeType1 : ModeType1, SpecialModeCommon { } class SpecialModeType2 : ModeType2, SpecialModeCommon { } class ModeManager { static Mode* GetMode(); }
The following will not compile since SpecialModeCommon does not extend Mode.
I can do a C style cast to get it to compile but that results in data being written to odd places and things not working.Code:SpecialModeCommon* mode = static_cast<SpecialModeCommon*>(ModeManager::GetMode());
For some reason not understood by me, dynamic_cast does not work in the environment I am working in. I don't understand why but assume I don't have dynamic_cast available (would that even solve this problem?)
Any assistance would be appreciated.




Reply With Quote