Re: Multiple destructors?
- From: "Tom de Neef" <tdeneef@xxxxxxxx>
- Date: Tue, 10 Jan 2006 14:46:05 +0100
"Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx> schreef in bericht
news:43c2dfd8$0$11065$e4fe514c@xxxxxxxxxxxxxxxxx
> Hello all,
>
> Has anyone here ever written a class with more than one destructor?
> I was just toying with some hobby code where objects are used to model
> a filesystem, and wondering how I might add the feature of deleting
> files and directories[0]. There are filesystem, file, and directory
> objects, and it seemed to me that destroying a file object might be a
> very natural way to also delete the corresponding file.
>
> File and directory objects are owned by their parents and freeing a
> filesystem object obviously shouldn't format its backing storage. So
> "the" destructor is taken, as it were. Then it occurred to me that
> Delphi doesn't stop me from having two destructors. Does anyone have
> thoughts on that? (I'm looking to Marco in particular, as Google
> revealed that FreePascal _will_ stop me from having two destructors.)
>
> I realise that it is very convenient to say the least to have only
> the standard Destroy destructor. But does it go beyond convenience?
>
> It is possible to have detached file and directory objects, that do
> not represent an allocated object in the actual filesystem. Should I
> take this as an argument against this way of deleting files?
>
> Groetjes,
> Maarten Wiltink
>
I remember an application where I had called destructors in a derived
class of Tlist DONE instead of DESTROY.
Destroy would just destroy the list, but leave its elements intact. Done
would first free all elements and then free the list. But at one place I
messed it up because I hadn't realized that Destroy has a special meaning.
For it is the destructor called by Free. And if you are in the habit of
calling Free you may have memory leaks when there isn't a Destroy in the
class.
Tom
.
- Follow-Ups:
- Re: Multiple destructors?
- From: Maarten Wiltink
- Re: Multiple destructors?
- References:
- Multiple destructors?
- From: Maarten Wiltink
- Multiple destructors?
- Prev by Date: Re: Help reducing object instance size
- Next by Date: Re: Getting the text under the cursor from any application
- Previous by thread: Re: Multiple destructors?
- Next by thread: Re: Multiple destructors?
- Index(es):
Relevant Pages
|