![]() |
Здравствуйте, гость ( Вход | Регистрация )
![]() |
Andrew Selivanov |
![]() ![]()
Сообщение
#1
|
![]() Участник ![]() ![]() Группа: Участник Сообщений: 249 Регистрация: 9.10.2007 Из: Москва Пользователь №: 3 Спасибо сказали: 15 раз(а) Репутация: ![]() ![]() ![]() |
Расположение в памяти для Множественного и Виртуального наследования
Memory Layout for Multiple and Virtual Inheritance (By Edsko de Vries, January 2006) http://www.phpcompiler.org/doc/virtualinheritance.html Warning. This article is rather technical and assumes a good knowledge of C++ and some assembly language. In this article we explain the object layout implemented by gcc for multiple and virtual inheritance. Although in an ideal world C++ programmers should not need to know these details of the compiler internals, unfortunately the way multiple (and especially virtual) inheritance is implemented has various non-obvious consequences for writing C++ code (in particular, for downcasting pointers, using pointers to pointers, and the invocation order of constructors for virtual bases). If you understand how multiple inheritance is implemented, you will be able anticipate these consequences and deal with them in your code. Also, it is useful to understand the cost of using virtual inheritance if you care about efficiency. Finally, it is interesting :-) Multiple Inheritance First we consider the relatively simple case of (non-virtual) multiple inheritance. Consider the following C++ class hierarchy.
Using a UML diagram, we can represent this hierarchy as ![]() Note that Top is inherited from twice (this is known as repeated inheritance in Eiffel). This means that an object bottom of type Bottom will have two attributes called a (accessed as bottom.Left::a and bottom.Right::a). How are Left, Right and Bottom laid out in memory? We show the simplest case first. Left and Right have the following structure: |
|
|
![]() ![]() ![]() |
![]() |
|
Текстовая версия | Сейчас: 8.6.2025, 9:25 |