Как стать автором
Обновить
6
0
Dmitriy Volkov @Dmitriy_Volkov

Project management / c++ development

Отправить сообщение

Diamond inheritance problem is not a problem, that's a tricky feature

Время на прочтение7 мин
Количество просмотров4.1K

General


Before discussing the topic I’d like to start with a general suggestion not to use multiple inheritance and especially diamond unless you are strongly forced to. You may use e.g. composition or aggregation instead.


Well, “Diamond inheritance problem” is some kind of steady expression which formed many years ago. You can easily find a lot of articles suggesting usage of “virtual public” to avoid the ambiguity and so on. For instance, https://en.wikipedia.org/wiki/Multiple_inheritance


image


 That is not wrong as for the problem stated but anyway it is quite one-side statement.
 Below you can find:


  • difference in memory allocation and initialization order between public and public virtual inheritance (examples 1, 2),
  • examples of practical usage of both public and public virtual inheritance (examples 3, 4).
Read more →
Всего голосов 4: ↑4 и ↓0+4
Комментарии0

Информация

В рейтинге
Не участвует
Откуда
Одесса, Одесская обл., Украина
Зарегистрирован
Активность