home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Temporaries
- Message-ID: <1992Dec15.143406.5353@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1992Dec6.204110.3073@news.cs.brandeis.edu>
- Date: Tue, 15 Dec 1992 14:34:06 GMT
- Lines: 51
-
- In article <1992Dec6.204110.3073@news.cs.brandeis.edu> dernis@binah.cc.brandeis.edu writes:
- >Hi,
- > Could someone explain how temporaries are identified and handled?
-
- A class with properly defined constructors and destructors will
- be handled 'just like an int'.
-
- >If an overloaded operator produces a temporary(by declaring a new variable)
- >to hold the result of an arithemetic op how is it destroyed?
-
- Wrong question. Right question: *When* is it destroyed?
- Answer: it is implementation defined, the upcoming standard
- ought to have more words on this, however.
-
- >What if the
- >operator returns a pointer to it? Is the compiler smart enough not to destroy
- >it?
-
- Same as if the object was an int. Return a pointer to an object
- on the stack, the pointer dangles. Return a pointer to a heap object,
- its up to you to delete it. Best to return a copy of the object,
- then the compiler deletes it.
-
- >
- >If it an object with an array type allocated dynamically, the destructor will
- >have to include a delete statement to get rid of the array, right? If info is
- >passed by reference then two objects will share the same array, if one of the
- >objects is destroyed what happens to the array?
-
- It is deleted, just like you told the system to delete it.
- The other reference is trash. Same as for int.
- >
- >I would appreciate an answer on the net, either a response or FAQ list
- >(how do you access the FAQ list?). I am out of money after buying the
- >computer, compiler, and Lippman's book C++ Primer. Does he discuss
- >this? I couldn't find it, but I haven't really looked through it
- >thoroughly?
-
- None of these issues really differ from the same questions
- in C. All that differs is that you can now make new types
- that act like 'int'.
-
- While there are other techniques, using this idiom
- is a good was to start off. See Coplien for explict details of how to
- write classes using the Orthodox Idiom.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-