Consequences of changing inheritance to virtual?

后端 未结 4 1293
礼貌的吻别
礼貌的吻别 2020-12-31 15:50

I\'m working on a huge project that I didn\'t start. My task is to add some additional functionality to what already is there. I\'m in a situation where I have to use virtua

4条回答
  •  悲哀的现实
    2020-12-31 16:50

    In addition to what Simon Richter said about calling constructors, using virtual inheritance means that you should be a bit more careful with your casts: You need to use dynamic_cast<> whenever you downcast a pointer in a hierarchy that includes virtual inheritance, as the relative offset between the base object and the goal type of the cast depends on the concrete actual type of the object. Other than that, everything else should work as expected.

提交回复
热议问题