I have two questions to ask...
a)
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(){} }; 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,
C* c = new D(); c->f2(); // Since there is no virtual pointer corresponding to the virtual function defined in f2(). How is the late binding done ?..
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 ?...
sizeof(*c); // It would be 24 and not 28.. Why ?...
Also say, considering the above code, i do this ,
void (C::*a)() = &C::f; void (C::*b)() = &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->(*a)(); c1->(*b)(); // Inspite of a and b having the same address, the function invoked is different. How is the definition of the function bounded here ?...
Hope I get a reply soon.