home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- 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
- From: pete@borland.com (Pete Becker)
- Subject: Re: Why X::X(X &a), not X::X(X a) ?
- Message-ID: <1993Jan23.192343.6985@borland.com>
- Originator: pete@genghis.borland.com
- Sender: news@borland.com (News Admin)
- Organization: Borland International
- References: <1993Jan15.092416.1@ualr.edu> <884@ulogic.UUCP> <1993Jan20.130006.1@ualr.edu>
- Date: Sat, 23 Jan 1993 19:23:43 GMT
- Lines: 26
-
- In article <1993Jan20.130006.1@ualr.edu> hood%eivax@ualr.edu writes:
- >In article <884@ulogic.UUCP>, hartman@ulogic.UUCP (Richard M. Hartman) writes:
- >> In article <1993Jan15.092416.1@ualr.edu> hood%eivax@ualr.edu writes:
- >>> Since the copy constructor should not normally
- >>>modify the source object a better declaration would be X::X( const X a)
- >>
- >> I am assuming a typo. Shouldn't that be:
- >>
- >> X::X(const X &a) ?
- >>
- >
- >Your right, it was a typo; the way you show it is correct.
- >
-
- Just to be sure there's no confusion:
-
- X::X(X&); // copy constructor
- X::X(const X&); // copy constructor
-
- Both are legal, and both are "correct". Most of the time you'll want
- the const version, but it's not inconceivable that someone might want a
- copy constructor that takes a non-const parameter. The ARM has rules for how
- the compiler deals with both types when it has to generate a copy constructor.
- -- Pete
-
-
-