Article View: comp.std.c++
Article #2286Re: Q: is A a = 100; equivalent to A a (10
From: Steve Clamage
Date: Mon, 23 Oct 1995 18:42
Date: Mon, 23 Oct 1995 18:42
52 lines
2088 bytes
2088 bytes
In article 814175813@cadlab, martelli@cadlab.cadlab.it (Alex Martelli) writes:
>matt@godzilla.EECS.Berkeley.EDU (Matt Austern) writes:
> ...
>>Sort of. If a is of class A, if the copy constructor X::X(const X&)
>>exists, and if the converting constructor X::X(const A&) exists and
>>isn't qualified as explicit, then "X x(a)" simply invokes the
>>converting constructor while "X x=a" invokes the converting
>>constructor and then the copy constructor.
The above characterization is not entirely correct. See 12.6.1, 8.5, and 12.2.
>So, to clarify my understanding -- the following program...:
>
>--cut tc.cc
>#include <iostream.h>
>
>class A { };
>
>class X {
>public:
> X(const X&) {
> cout<<"X::copy ctor"<<endl;
> }
> X(const A&) {
> cout<<"X::ctor(A&)"<<endl;
> }
>};
>
>int
>main()
>{
> A a;
> X x1 = a;
According to 12.6.1 and 8.5, the A is converted to an X, which
is then copied to x1. But according to 12.2, referenced in 8.5, the
temporary in this case may be omitted. Thus, you might, but need not,
get a call of X(const X&).
> X x2(a);
According to 12.6.1 and 8.5, no temporary X object may be created and
copied, so you must not have a call of X(const X&).
---
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:
<46gn60$753@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageReferences:
<martelli.814175813@cadlab>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: clamage@Eng.sun.com (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Q: is A a = 100; equivalent to A a (10 Date: 23 Oct 1995 18:42:26 GMT Organization: Sun Microsystems Inc. Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <46gn60$753@engnews2.Eng.Sun.COM> References: <martelli.814175813@cadlab> Reply-To: clamage@Eng NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: taumet.eng.sun.com Content-Length: 1262 X-Lines: 48 Originator: clamage@taumet