From: Wayne Price (W.Price++at++electronic-alchemy.co.uk)
Date: 12/15/2002 02:06:11
Yosi.Halakhmi++at++inoviatele.com wrote:
>
> class A { ...};
>
> class B {
> ...
>
> A a;
> int i;
> };
>
> main() {
> B* bp = new B;
> ...
> A* ap = (A*) bp;
> ...
> delete ap; // do we have here memory leak ?
>
> }
This isn't valid anyway, and I would EXPECT there to be problems.
You can't just cast from one class to another, especially if they
are not related.
It will work if your destructors are virtual, AND it's a valid
cast, i.e.
class A
{
...
virtual ~A();
...
};
class B : public A
{
...
virtual ~B();
...
};
This is standard C++
Wayne
-- ___________________________________________________________________________ Wayne Price W.Price++at++electronic-alchemy.co.uk Electronic Alchemy Ltd Mobile: +44 (0) 7770 376383 Home: +44 (0) 1483 531235
This archive was generated by hypermail 2b29 : Sun Dec 15 2002 - 02:10:16 PST