Witam,
Nie wiem czy do konca rozumiem zasade dzialania VTABLE wiec mam pytanie. Na poczatku pokaze przyklad.
Mam przykładowo klasy:
class B1
{
public:
void f0() {}
virtual void f1() {}
int int_in_b1;
};
class B2
{
public:
virtual void f2() {}
int int_in_b2;
};
class D : public B1, public B2
{
public:
void d() {}
void f2() {} // override B2::f2()
int int_in_d;
};
i Robiąc coś takiego:
D *d = new D();
To pamięć dla obiektu "d" wygląda tak:
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)
+16: value of int_in_b2
+20: value of int_in_dA tutaj VTABLE D (dla B1)::
+0: B1::f1()
+4: D::~D()
+8: D::d()
+12: D::f2()A tutaj VTABLE D (dla B2::
+0: D::f2()
+4: D::~D()
Takze to rozumiem jest logiczne, ale teraz mam pytanie gdyby układ klas był następujący:
B1 <--- B2 <--- D
Czyli:
class B1
{
public:
void f0() {}
virtual void f1() {}
int int_in_b1;
};
class B2, public B1
{
public:
virtual void f2() {}
int int_in_b2;
};
class D : public B2
{
public:
void d() {}
void f2() {} // override B2::f2()
int int_in_d;
};
??
Z gory dziekuje za odp.