I'm having trouble debugging a project in Visual Studio C++ 2008 with pointers to objects that have virtual multiple inheritance. I'm unable to examine the fields in the derived class, if the pointer is a type of a base.
A simple test case I made:
class A
{
public:
A() { a = 3; };
virtual ~A() {}
int a;
};
class B : virtual public A
{
public:
B() { b = 6; }
int b;
};
class C : virtual public A
{
public:
C() { c = 9; }
int c;
};
class D : virtual public B, virtual public C
{
public:
D() { d = 12; }
int d;
};
int main(int argc, char **argv)
{
D *pD = new D();
B *pB = dynamic_cast<B*>(pD);
return(0);
}
Put a breakpoint on the "return(0)", and put pD and pB in the watch window. I can't figure out a way to see "d" in the pB in the watch window. The debugger won't accept a C style cast, or dynamic_cast. Expanding to the v-table shows that the debugger knows it's actually pointing a D destructor, but no way to see "d".
Remove the "virtual's" from the base class definitions (so D has 2 A's) and the debugger will let me expand pB and see that it's really a D* object which can be expanded. This is what I want to see in the virtual case as well.
Is there any way to make this work? Do i need to figure out the actual offsets of the object layout to find it? Or is it time to just say I'm not smart enough for virtual multiple inheritance and redesign, cause the actual project is much more complicated, and if I can't debug, I should make it simpler :)