Topic: Q: is A a = 100; equivalent to A a (100);


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/10/13
Raw View
In article 95Oct12202250@ludo.two-oo-one.fr, jlm@two-oo-one.fr (Jean-Louis Moser) writes:
>| According to the standard, are the two lines of the main
>| equivalent ? My Opinion is yes, but one of my compilers would
>| like to access copy contructor to be happy with the
>| second line as if it would like to build a2 from a temporary A
>| which would be build from the int value 99. If we make copy
>| constructor public, this one isn't called, but the compiler
>| is happy. Thank you for answers.

That compiler is correct. If the copy constructor is not accessible,
the line
 A a2 = 99;
is invalid. Access to the copy constructor is required, even if the
compiler chooses to optimize away the actual call.

>
>#include <iostream.h>
>
>class A {
>public:
>    A (int i) {cout << "A" << endl;}
>private:
>    A (const A&) {cout << "COPY" << endl;}
>};
>
>void main ()
>{
>    A a1 (100);
>    A a2 = 99;
>}


---
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. ]