Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Why do cons...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 23 of 23 Topic 43340 of 48417
Post > Topic >>

Re: Why do constructors have same name as the class ?

by peter koch <peter.koch.larsen@[EMAIL PROTECTED] > Feb 28, 2008 at 04:08 PM

On 29 Feb., 00:17, "Ole Nielsby" <ole.niel...@[EMAIL PROTECTED]
> wrote:
> In the Middle of the Pack <a...@[EMAIL PROTECTED]
> wrote:
>
> > Now, a destructor is going to destroy an instance, so it can return
> > neither
> > its object nor any part of its object. Just what else might you like
it =
to
> > return?
>
> Fx the size of the now-vacant memory block.
>
> I wrote an interpreter for a language with a reference-counted data
> model. To keep memory footprint small, I want to be able to use a
> custom allocator that doesn't use extra space for administration. For
> this to work, the size of the garbage chunks must be inferred from the
> objects at destruction time.
>
> I defined a method =A0 =A0unlinkAndGetSize() =A0 =A0which is essentially
a=
 value-
> returning destructor - this works for me, but my code might have come
> out somewhat more elegant if I could have returned this value from the
> destructor.

But that is an implementation detail. The book "Inside the C++ object
model" by Stan Lippman gives lots of examples about how to implement
the C++ code. If I remember correctly, returning the size of the
object from the destructor was useful in some situations (I do not
remember them any more, thats just one more reason for you to buy the
excellent book!),

/Peter
 




 23 Posts in Topic:
Why do constructors have same name as the class ?
yeti <rohin.koul@[EMAI  2008-02-15 08:27:05 
Re: Why do constructors have same name as the class ?
"Fabian Lenzen"  2008-02-15 17:31:47 
Re: Why do constructors have same name as the class ?
Tim Slattery <Slattery  2008-02-15 16:11:50 
Re: Why do constructors have same name as the class ?
"Mike Wahler" &  2008-02-15 09:05:23 
Re: Why do constructors have same name as the class ?
red floyd <no.spam@[EM  2008-02-15 09:36:41 
Re: Why do constructors have same name as the class ?
James Kanze <james.kan  2008-02-15 13:04:52 
Re: Why do constructors have same name as the class ?
"Alf P. Steinbach&qu  2008-02-15 22:28:29 
Re: Why do constructors have same name as the class ?
Ian Collins <ian-news@  2008-02-16 10:40:15 
Re: Why do constructors have same name as the class ?
"Victor Bazarov"  2008-02-15 16:49:31 
Re: Why do constructors have same name as the class ?
Ian Collins <ian-news@  2008-02-16 11:01:45 
Re: Why do constructors have same name as the class ?
Andre Kostur <nntpspam  2008-02-15 22:21:52 
Re: Why do constructors have same name as the class ?
Raymond <raymond@[EMAI  2008-02-16 12:52:02 
Re: Why do constructors have same name as the class ?
James Kanze <james.kan  2008-02-16 00:48:34 
Re: Why do constructors have same name as the class ?
yeti <rohin.koul@[EMAI  2008-02-16 06:47:35 
Re: Why do constructors have same name as the class ?
yeti <rohin.koul@[EMAI  2008-02-16 06:53:40 
Re: Why do constructors have same name as the class ?
Ian Collins <ian-news@  2008-02-17 08:31:53 
Re: Why do constructors have same name as the class ?
James Kanze <james.kan  2008-02-16 12:56:30 
Re: Why do constructors have same name as the class ?
In the Middle of the Pack  2008-02-26 19:04:24 
Re: Why do constructors have same name as the class ?
"Ole Nielsby" &  2008-02-29 00:17:17 
Re: Why do constructors have same name as the class ?
"jason.cipriani@[EMA  2008-02-26 19:32:38 
Re: Why do constructors have same name as the class ?
"jason.cipriani@[EMA  2008-02-26 19:38:37 
Re: Why do constructors have same name as the class ?
James Kanze <james.kan  2008-02-27 01:31:57 
Re: Why do constructors have same name as the class ?
peter koch <peter.koch  2008-02-28 16:08:23 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 10:31:13 CST 2008.