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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!mole-end!mat
  3. From: mat@mole-end.matawan.nj.us
  4. Subject: Re: destruction of temporaries
  5. Message-ID: <1992Aug14.171659.14578@mole-end.matawan.nj.us>
  6. Summary: When to allow copy constructors
  7. Organization: :
  8. References: <46140@sunquest.UUCP> <rmartin.713716434@thor>
  9. Date: Fri, 14 Aug 1992 17:16:59 GMT
  10. Lines: 42
  11.  
  12. In article <rmartin.713716434@thor>, rmartin@thor.Rational.COM (Bob Martin) writes:
  13. > bill@sunquest.UUCP (Bill Raves) writes:
  14.  
  15. > Giving the compiler access to the copy semantics of a class is a
  16. > design decision which must be made carefully.  It should not be done
  17. > in every case.  Many so called "cannonical forms" recommend the
  18. > unquestioned inclusion of copy constructors and assigment operators.
  19. > I disagree with this approach.  Copy semantics are often too complex
  20. > to be allowed into general use.  
  21.  
  22. > Whenever you provide a regular copy constructor, you are granting
  23. > permission to the compiler to make temporaries.  This must be a
  24. > conscious choice, and must be supported by construction and
  25. > destruction semantics which are valid in any context.
  26.  
  27. I'd like to offer some criteria to consider when making this decision.
  28.  
  29. The principle question, IMO, is `What are the relationships that the
  30. object is involved with?'
  31.  
  32. If the object is involved with problem-domain relationships wherein the
  33. object present in memory represents a cardinality-specific entity in the
  34. problem, you cannot use a naive copy constructor and may not be able to
  35. use any.  (e.g. you can't allow random copies of the object that represents
  36. TheCEO, but you can allow any number of copies of the character array that
  37. represents the CEO's name.)
  38.  
  39. If the object is involved with solution-domain relationships, and the
  40. related objects lie entirely within the object (e.g. the real and
  41. imaginary parts of a complex number) this relationship poses no
  42. obstacle to copy construction.  But if the relationship involves objects
  43. or entities (e.g. resources) outside the object (e.g. a String class
  44. that allocates memory) either a special copy constructor is needed or
  45. else no copy constructor is sensible.
  46.  
  47. Anyone who can express this more clearly and put it in a good textbook
  48. deserves to make some money off it.
  49. -- 
  50.  (This man's opinions are his own.)
  51.  From mole-end                Mark Terribile
  52.  
  53.  mat@mole-end.matawan.nj.us, Somewhere in Matawan, NJ
  54.