home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12346 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.5 KB  |  50 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!destroyer!sol.ctr.columbia.edu!eff!world!pkturner
  3. From: pkturner@world.std.com (Prescott K Turner)
  4. Subject: Re: Temporary variables and unnamed objects
  5. Message-ID: <BszD04.7Ao@world.std.com>
  6. Keywords: Constructors,temporary,unnamed
  7. Organization: The World Public Access UNIX, Brookline, MA
  8. References: <1992Aug10.143831.29819@bnr.ca>
  9. Date: Fri, 14 Aug 1992 15:43:15 GMT
  10. Lines: 38
  11.  
  12. Rene Tio writes:
  13. > On one hand, the ARM says the only operations allowed on temporaries are
  14. > assignments and binding of references, on the other hand, code such as:
  15. >   class Object {
  16. >       Object(int) { ... }
  17. >       void doSomething(void) { ... }
  18. >   };
  19. >   Object a(2), b(3);
  20. >   Object c = a + b / 2
  21. > where the temporary created by (a + b) is operated on by "/".
  22.  
  23. That's an omission in the ARM.
  24.  
  25. > In addition the ARM does not make clear whether
  26. >   Object(1)
  27. > is a temporary, but only says it is an "unnamed object".
  28.  
  29. When Object(1) is an unnamed object, it is a temporary.
  30.  
  31. > Finally, the ARM says that the constructor is not true a callable function
  32. > which has no return type, yet cfront allows:
  33. >   Object(3).doSomething()
  34. > which implies that constructors *DO* return values (i.e., the object being
  35. > constructed,) and that it returns an lvalue.
  36.  
  37. Here, you've made the common error of mistaking Object(3) for a function
  38. call, when it's actually an explicit conversion (ARM 5.2.3).
  39. --
  40. Prescott K. Turner, Jr.
  41. 13 Burning Tree Rd., Natick, Massachusetts USA
  42. Internet: pkturner@world.std.com
  43.