Article ID: 143082
Article Last Modified on 7/5/2005
// Compile option needed: none
// File test.cpp
truct A {
struct Nested {
virtual void A_Func() = 0;
};
};
truct B {
struct Nested {
virtual void B_Func() = 0;
};
};
truct MyClass : public A::Nested, public B::Nested
{
void A_Func() { cout << "A_Func() called" << endl; }
void B_Func() { cout << "B_Func() called" << endl; }
};
void main()
{
MyClass m;
cout << "(A::Nested*)&m = " << (void*)(A::Nested*)&m << endl;
cout << "(B::Nested*)&m = " << (void*)(B::Nested*)&m << endl;
((A::Nested*)&m)->A_Func();
((B::Nested*)&m)->B_Func();
}
In this example, the compiler confuses (A::Nested*) and (B::Nested*), so
the same values are printed for both ((A::Nested*)&m) and ((B::Nested*)&m)
when they should be different. This also causes the call to B_Func on the
last line to call A_Func instead.
Keywords: kbbug kbfix kbvc600fix KB143082