Re: Multiple inheritance and pointer equivalence
* Danny Woods:
Hi all,
Given this simple program:
----
#include <cstdio>
class A { public: virtual ~A() {} };
class B { public: virtual ~B() {} };
class C : public A, public B { public: virtual ~C() {} };
int main(void)
{
C *c = new C();
A *a = c;
B *b = c;
printf("c: %p; a: %p; b: %p\n", c, a, b);
delete c;
return 0;
}
----
Is it to be expected that the addresses stored in a and b are different?
Of course.
In general they must be, since those are pointers directly to A and B objects.
I've tried this with Visual C++ and Cygwin g++, with identical results.
The problem I have is that there are other subclasses of A and B that
are distinct, but that there's a special case where the combined
subclass, C, is required to fill both roles. When the code that cleans
up a and b runs later, I'll end up with double deletion
Try C++ destructors, they're good at cleanup.
unless I can
reliably tell that a and b point to the same object, but the simple
'a == b' doesn't work here.
Don't do that.
Cheers & hth.,
- Alf