In C++, should I almost always use virtual inheritance?

前端 未结 2 758
囚心锁ツ
囚心锁ツ 2020-12-10 00:30

I see from this entry that virtual inheritance adds sizeof(pointer) to an object\'s memory footprint. Other than that, are there any drawbacks to me just using virtual inher

2条回答
  •  余生分开走
    2020-12-10 01:19

    In my experience, virtual inheritance (as opposed to virtual methods) is almost never needed. In C++ it's used to address the "diamond inheritance problem", which if you avoid multiple inheritance cannot actually happen.

    I'm pretty sure that I've never encountered virtual inheritance outside C++ books, which includes both code I write and million+ line systems I maintain.

提交回复
热议问题