home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20000 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.5 KB  |  54 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!news.univie.ac.at!scsing.switch.ch!univ-lyon1.fr!ghost.dsi.unimi.it!batcomputer!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Question of scope
  5. Message-ID: <1993Jan27.153140.21532@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1993Jan22.184558.21397@porthos.cc.bellcore.com>
  10. Date: Wed, 27 Jan 1993 15:31:40 GMT
  11. Lines: 41
  12.  
  13. In article <1993Jan22.184558.21397@porthos.cc.bellcore.com> chw@bellcore.com writes:
  14. >
  15. >A (novice) question about scope.
  16.  
  17.     Not a novice question! One thats got the committee
  18. stumped.
  19. >void foo(Base *p) 
  20. >{ 
  21. >  p->Draw(); 
  22. >} 
  23. >Anyway, does the following call the destructor just after returning
  24. >from the foo?
  25. >   foo(& Derived1());
  26. >Does it have any ugly portability problems? 
  27.  
  28.     Yes. The lifetime of temporary objects is not well
  29. defined yet. The code
  30.  
  31.     void foo(const Base &b)
  32.     {
  33.         b.Draw();    
  34.     }
  35.  
  36. is safer since any compiler that deleted the temporary argument
  37.  
  38.     foo(Derived1());
  39.  
  40. would invalidate a lot of code. But even this is not
  41. yet guarranteed to be safe (although it probably will be
  42. in the Standard).
  43.  
  44.  
  45. -- 
  46. ;----------------------------------------------------------------------
  47.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  48.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  49. ;------ SCIENTIFIC AND ENGINEERING SOFTWARE ---ph:  2 799 8223 --------
  50.