Virtual Functions Dilemma in C++
<p>I have two questions to ask...</p>

<p>a) </p>

<pre><code>Class A{
int a;
public:
virtual void f(){}
};

Class B {
int b;
public:
virtual void f1(){}
};

Class C: public A, public B {

int c;
public:
virtual void f(){} // Virtual is optional here
virtual void f1(){} // Virtual is optional here

virtual void f2(){}

};

Class D: public C {
int d;
public:
void f2(){}

};
</code></pre>

<p>Now C++ says that there won't be 3 virtual pointers in C's instance but only 2. And then, how could a call to say,</p>

<pre><code>C* c = new D();
</code></pre>

<p><code>c-&gt;f2();</code> // Since there is no virtual pointer corresponding to the virtual function defined in f2(). How is the late binding done ?..</p>

<p>I read saying that , the virtual pointer to this function is added in the virtual pointer of the first super class of C. Why is that so ?.. Why is there no virtual table ?...</p>

<p>sizeof(*c); // It would be 24 and not 28.. Why ?...</p>

<p>Also say, considering the above code, i do this ,</p>

<pre><code>void (C::*a)() = &amp;C::f;
void (C::*b)() = &amp;C::f1;

printf("%u", a); 
printf("%u",b);

// Both the above printf() statements print the same address. Why is that so ?...
// Now consider this,

C* c1 = new C();

c1-&gt;(*a)();

c1-&gt;(*b)();
</code></pre>

<p>// Inspite of a and b having the same address, the function invoked is different. How is the definition of the function bounded here ?...</p>

<p>Hope I get a reply soon.</p>
