On May 7, 4:25 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
Branimir Maksimovic wrote:
It will call copy constructor all right, but
still gives error that it wants A(A)
Sorry, I don't know what you mean here.
I had to wait several hours to be sure that this is
not already sent, because I clicked send twice
but google didn't confirmed.
Ok, following program does not compiles:
class A{
public:
A(){}
A(A&){}
};
A foo()
{
A a;
return a;
}
int main()
{
A a;
a = foo();
}
bmaxa@maxa:~$ g++ -Wall cctor.cpp -o cctor
cctor.cpp: In function ?int main()?:
cctor.cpp:16: error: no matching function for call to ?A::A(A)?
cctor.cpp:4: note: candidates are: A::A(A&)
Since temporary is constructed by local variable now, I think
that this should compile since A::A(A&) should be called.
But I got same error again.
That is what confuses me. Is compiler right or should
this compile?
Thanks for your time (I'm really rusty with English language)
It seems like g++ is in the wrong. Compiles fine with MSVC 7.1 and with Comeau
Online. Since Comeau is very seldom wrong, it indicates that the code is
correct and should compile, i.e. that the standard doesn't give the compiler
initialized from temporary).
A: Because it messes up the order in which people normally read text.
A: Top-posting.