* Branimir Maksimovic:
> On May 7, 4:25 pm, "Victor Bazarov" <v.Abaza...@[EMAIL PROTECTED]
> 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@[EMAIL PROTECTED]
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 tem****ary 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
latitude to introduce an additional intermediate tem****ary (which couldn't
be
initialized from tem****ary).
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


|