Okay, this is a little complicated. Here is the (simplified) code:
class A
{
virtual ~A();
};
class B
{
virtual ~B();
};
class Derived : public A, public B
{
Derived();
Derived(const B& b);
};
C Derived::Derived(const B& b)(i.e., taking one of its grounds) as follows
Derived::Derived(const B& b)
{
*static_cast<B*>(this) = b;
}
For me, this is something in the line “just don't do it”, but that the existing code and we are experiencing subtle memory corruption are suspiciously next to this code. So I'm curious if this is good.
The curious part here is that both base classes have vtables, and none of them have explicit copy / assignment constructors / operators.
In my opinion, the memory layout for the class is Derivedas follows
`Derived`
---------
A-vtable
A-fields
B-vtable
B-fields
, "B", B-vtable, , "A", A-vtable, vtables .
/ copy/assign B B-fields, *static_cast<B*>(this) = b; (static_cast B-fields, B-vtable , AFAIK).
, , , , . ? - , ( MSVC 2012 )?
: , / , . , , , , .