I read an article on virtual table in Wikipedia.
class B1
{
public:
void f0() {}
virtual void f1() {}
int int_in_b1;
};
class B2
{
public:
virtual void f2() {}
int int_in_b2;
};
used to derive the following class:
class D : public B1, public B2
{
public:
void d() {}
void f2() {} // override B2::f2()
int int_in_d;
};
After reading it I couldn't help but wonder how non virtual member functions are implemented in C++. Is there a separate table like the v-table in which all the function addresses are stored? If yes, what is this table called and what happens to it during inheritance?
If no then how does compiler understand these statements?
D * d1 = new D;
d1->f0(); // statement 1
How does compiler interpret that f0() is function of B1 and since D has publicly inherited D it can access f0(). According to the article the compiler changes statement 1 to
(*B1::f0)(d)