I'm new so go easy on me :) From what my lecturer had told some time ago, the order of the virtual table is important. But I do not understand the reason for that!!?
Given the next code :
class A
{
public:
A() {cout <<"1" << endl;};
A (const A& s) {cout << "2" << endl;}
~A () {cout << "3" << endl;}
void f1() {cout << "4" << endl; f2();}
virtual void f2() = 0;
virtual void f3() {cout << "5" << endl;}
};
class B : public A
{
public:
B() {cout << "6" << endl;}
B(const B& b) : A(b) {cout << "7" << endl;}
~B() {cout << "8" << endl;}
virtual void f1() {cout<<"9"<<endl;}
void f2() {cout<<"lO"<<endl; f4();}
virtual void f2(int i) {cout << "11" << endl;}
virtual void f4() {cout << "12" << endl; f3();}
};
He said that the order is :
A's vtable :
A::f2()
A::f3()
B's vtable :
B::f2()
A::f3()
B::f1()
B::f2(int)
B::f4()
But I don't understand why it is important? He said that the vtable is useless if it's not by its correct order, can you please explain why?