Article View: comp.std.c++
Article #2339Re: Q: is A a = 100; equivalent to A a (10
From: Steve Clamage
Date: Sun, 29 Oct 1995 01:54
Date: Sun, 29 Oct 1995 01:54
33 lines
1769 bytes
1769 bytes
In article 814802135@cadlab, martelli@cadlab.cadlab.it (Alex Martelli) writes: >clamage@Eng.Sun.COM (Steve Clamage) writes: > ... >>It is sometimes also necessary to point out the difference between copy >>construction and copy assignment. >> // T is a type, and x is not type T >> T t1 = x; // may omit a temp T and avoid copying it >> T t2; >> t2 = x; // must create a temp T and assign it to t2 > >This only applies if class T does not define an "operator=(X const&)" >(or, similar ones taking an X or an X&), where x's type is X, right? Right. I was trying to make the point that copy construction can sometimes be omitted, but copy assignment cannot be optimized away. (Modulo the "as-if" rule. If you can't detect a difference, there isn't a difference.) Once again, I only point this out to emphasize that you should design classes so that the correctness of the program does not depend on whether extra temporaries are created and copied. The language definition allows implementors considerable leeway in creating or avoiding temps. --- Steve Clamage, stephen.clamage@eng.sun.com --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<MATT.95Oct28175430@Austern>Path:
arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!MattReferences:
<martelli.814802135@cadlab>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Q: is A a = 100; equivalent to A a (10 Date: 29 Oct 1995 01:54:30 GMT Organization: Sun Microsystems Inc. Approved: Matt@Austern Message-ID: <MATT.95Oct28175430@Austern> References: <martelli.814802135@cadlab> Reply-To: clamage@Eng.Sun.COM NNTP-Posting-Host: austern.hip.berkeley.edu