Планировка памяти множественного объекта в C ++C++

Программы на C++. Форум разработчиков
Anonymous
Планировка памяти множественного объекта в C ++

Сообщение Anonymous »

Код: Выделить всё

class B1 {
virtual void f1();
int int_in_b1;
};
class B2 {
virtual void f2();
int int_in_b2;
};
class D: B1, B2 {
int int_in_d;
void f1();
void f2();
};
class D1: B1, B2 {
int int_in_d;
virtual void f1();
virtual void f2();
};
На основе этой статьи макет памяти для объекта d of class d похож на это:

Код: Выделить всё

d:
+0: pointer to virtual method table of D (for B1)
+4: value of int_in_b1
+8: pointer to virtual method table of D (for B2)
+12: value of int_in_b2
+16: value of int_in_d

virtual method table of D (for B1):
+0: D::f1()  // B1::f1() is overridden by D::f1()

virtual method table of D (for B2):
+0: D::f2()   // B2::f2() is overridden by D::f2()
< /code>

А как насчет объекта класса D1 < /code>? В классе D1 
участники f1 и f2 оба объявляются как виртуальные !

Подробнее здесь: https://stackoverflow.com/questions/307 ... bject-in-c

Вернуться в «C++»