Alf P. Steinbach wrote:
* Leigh Johnston:
All that's needed is inheritance.
Example? And don't say virtual inheritance.
Please quote enough of the article you're responding to to establish the
necessary context for your response. Not all readers have easy access to
the thread history.
Anyway, you're asking for and doubting the existence of this problem:
#include <assert.h>
struct A
{
int blah;
};
struct B: A
{
virtual ~B() {}
int doh;
};
int main()
{
B* p1 = new B;
A* p2 = p1;
void* pv1 = p1;
void* pv2 = p2;
assert( pv1 == pv2 ); // Uh oh, not guaranteed.
}
To some C++ programmers it comes as a surprise.
Note that the introduction of a virtual destructor in the derived class
is not necessary in order to have this problem, except that with that
it's easier to convince folks since then the assertion fails with two
popular compilers.