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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!paladin.american.edu!howland.reston.ans.net!usc!cs.utexas.edu!sun-barr!decwrl!borland.com!pete
  3. From: pete@borland.com (Pete Becker)
  4. Subject: Re: Why X::X(X &a), not X::X(X a) ?
  5. Message-ID: <1993Jan23.192343.6985@borland.com>
  6. Originator: pete@genghis.borland.com
  7. Sender: news@borland.com (News Admin)
  8. Organization: Borland International
  9. References: <1993Jan15.092416.1@ualr.edu> <884@ulogic.UUCP> <1993Jan20.130006.1@ualr.edu>
  10. Date: Sat, 23 Jan 1993 19:23:43 GMT
  11. Lines: 26
  12.  
  13. In article <1993Jan20.130006.1@ualr.edu> hood%eivax@ualr.edu writes:
  14. >In article <884@ulogic.UUCP>, hartman@ulogic.UUCP (Richard M. Hartman) writes:
  15. >> In article <1993Jan15.092416.1@ualr.edu> hood%eivax@ualr.edu writes:
  16. >>>  Since the copy constructor should not normally 
  17. >>>modify the source object a better declaration would be X::X( const X a)
  18. >> 
  19. >> I am assuming a typo.  Shouldn't that be:
  20. >> 
  21. >>     X::X(const X &a)    ?
  22. >> 
  23. >
  24. >Your right, it was a typo; the way you show it is correct.
  25. >
  26.  
  27.     Just to be sure there's no confusion:
  28.  
  29.     X::X(X&);    // copy constructor
  30.     X::X(const X&);    // copy constructor
  31.  
  32.     Both are legal, and both are "correct".  Most of the time you'll want
  33. the const version, but it's not inconceivable that someone might want a
  34. copy constructor that takes a non-const parameter.  The ARM has rules for how
  35. the compiler deals with both types when it has to generate a copy constructor.
  36.     -- Pete
  37.  
  38.  
  39.