Thanks laserlight,
I have made a sample below and the output is Derived1. I have monitored that the content of this object in the constructor of class Derived1 is,
My confusion is, why an additional hidden "vtordisp" fields exists? What is the issue described by the quoted statements in my original question?
- this 0x0022fc4c {j=-858993460 } Derived1 * const
- Base {i=100 } Base
- __vfptr 0x0109783c const Derived1::`vftable' *
[0] 0x01091037 [thunk]erived1::foo`vtordisp{4294967292,0}' (void) *
i 100 int
j -858993460 int
Code:
#include <iostream>
using namespace std;
class Base {
private:
int i;
public:
Base()
{
i = 100;
}
virtual void foo()
{
cout << "Base " << endl;
}
};
class Derived1 : virtual public Base {
private:
int j;
public:
Derived1()
{
Base* pb = this;
pb->foo(); // call Base class's virtual function inside derived class's
constructor by using pointed to base type
j = 200;
}
virtual void foo()
{
cout << "Derived1 " << endl;
}
};
class Derived2 : virtual public Base {
private:
int k;
public:
Derived2()
{
k = 300;
}
virtual void foo()
{
cout << "Derived2 " << endl;
}
};
class Final : public Derived1, public Derived2 {
private:
int t;
public:
Final()
{
t = 400;
}
virtual void foo()
{
cout << "Final " << endl;
}
};
int main()
{
Final f;
return 0;
}
Originally Posted by
laserlight
It is not a Windows programming question since it applies generally, but is a Microsoft specific implementation detail.
regards,
George