I am using Unreal’s SharedPtrs all around to work with objects of this class. At some point, I have this kind of code:
// Cast armor itemstats to EArmorStats to reveal durability info
auto armor = StaticCastSharedPtr<EArmorStats>(ArmorSlot->getStats()).ToSharedRef();
getStats() returns TSharedPtr of EternalStats , so I am casting down from EternalStats to EArmorStats. It is not super-safe, but should work properly. However I get an error:
cannot convert a 'EternalStats*' to a 'EArmorStats*'; conversion from a virtual base class is implied
So, is it because of virtual inheritance? As far as I recall, I used virtual inheritance in this case because of diamond problem (I inherit one more class from EternalStats and then inherit another class from both these classes).
Yeah, that’s what I was afraid of. But what if I “strip” the object out of smart ptr into the naked pointer and then do dynamic_cast? I know for sure that the pointer points to child class’s object. How bad is such code?