Where is the “virtual” keyword necessary in a complex multiple inheritance hierarchy?

后端 未结 7 1711
死守一世寂寞
死守一世寂寞 2021-01-30 19:00

I understand the basics of C++ virtual inheritance. However, I\'m confused about where exactly I need to use the virtual keyword with a complex class hierarchy. F

7条回答
  •  臣服心动
    2021-01-30 19:21

    My personal suggestion would be to start at B and C : virtual A, and then keep adding until the compiler stops complaining.

    In reality, I'd say that B and C : virtual A, G and H : virtual E, and E : virtual B and C. All the other inheritance links can be normal inheritance. This monstrosity would take like six decades to make a virtual call, though.

提交回复
热议问题