Article View: borland.public.cppbuilder.nativeapi
Article #7556Re: Self destructive 0bject/class... (Challange)
From: Remy Lebeau (TeamB)
Date: Wed, 08 Oct 2003 17:39
Date: Wed, 08 Oct 2003 17:39
25 lines
2580 bytes
2580 bytes
"FernandoF" <FernandoF@nospam.com> wrote in message news:3f842be6$1@newsgroups.borland.com... > Well, IMHO I should say that this way is a bit dangerous... Only if you don't use it correctly. Allowing on object to free' this' within itself is the basis for reference-counted objects, and is pivital to COM's architecture, for example, where *every* interface instance is a reference-counted object that frees 'this' when the reference count falls to 0 in the Release() method. That is one of the core rules to COM that all interfaces must support. > What if the object hasn't been created with new? Then you can't use 'delete', plain and simple. That is the responsibility of your own code to enforce, not the object's. Easiest way to enforce it is to declare an object's constructor as private, then the object's constructor cannot be called directly to begin with. The object won't be able to be placed on the stack at all, and if you then provide a static Create() function or a class factory, you can enforce that the object is always allocated on the heap via 'new'. Gambit
Technical Details
Message-ID:
<3f844b63$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!sn-xit-06!sn-xit-05!sn-xit-09!supernews.com!news-xfer2.atl.newshosting.com!63.218.45.10.MISMATCH!newshosting.com!news-xfer1.atl.newshosting.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!irazu.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f0c21da@newsgroups.borland.com> <3f0c4519$1@newsgroups.borland.com> <3f842be6$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,9af595df0adad9f3 X-Google-Attributes: gid10cc67,public X-Google-Thread: 10db1e,9af595df0adad9f3 X-Google-Attributes: gid10db1e,public X-Google-Thread: 102541,9af595df0adad9f3 X-Google-Attributes: gid102541,public X-Google-ArrivalTime: 2003-10-08 10:44:05 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi,borland.public.cppbuilder.oodesign,borland.public.cppbuilder.students References: <3f0c21da@newsgroups.borland.com> <3f0c4519$1@newsgroups.borland.com> <3f842be6$1@newsgroups.borland.com> Subject: Re: Self destructive 0bject/class... (Challange) Date: Wed, 8 Oct 2003 10:39:25 -0700 Lines: 27 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 67.22.137.75 Message-ID: <3f844b63$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1065634659 67.22.137.75 (8 Oct 2003 10:37:39 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!sn-xit-06!sn-xit-05!sn-xit-09!supernews.com!news-xfer2.atl.newshosting.com!63.218.45.10.MISMATCH!newshosting.com!news-xfer1.atl.newshosting.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!irazu.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail