Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Overload re...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 10 of 11 Topic 45791 of 47031
Post > Topic >>

Re: Overload resolution and copy constructors that take non-const

by "Alf P. Steinbach" <alfps@[EMAIL PROTECTED] > May 8, 2008 at 12:34 AM

* 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?
 




 11 Posts in Topic:
Overload resolution and copy constructors that take non-const re
Anthony Williams <anth  2008-05-07 10:44:48 
Re: Overload resolution and copy constructors that take non-cons
Branimir Maksimovic <b  2008-05-07 05:54:26 
Re: Overload resolution and copy constructors that take non-cons
"Victor Bazarov"  2008-05-07 08:59:18 
Re: Overload resolution and copy constructors that take non-cons
Branimir Maksimovic <b  2008-05-07 06:21:21 
Re: Overload resolution and copy constructors that take non-cons
Branimir Maksimovic <b  2008-05-07 06:40:00 
Re: Overload resolution and copy constructors that take non-cons
"Victor Bazarov"  2008-05-07 10:25:23 
Re: Overload resolution and copy constructors that take non-cons
dizzy <dizzy@[EMAIL PR  2008-05-07 17:47:00 
Re: Overload resolution and copy constructors that take non-cons
"Victor Bazarov"  2008-05-07 11:33:53 
Re: Overload resolution and copy constructors that take non-cons
Branimir Maksimovic <b  2008-05-07 15:18:46 
Re: Overload resolution and copy constructors that take non-cons
"Alf P. Steinbach&qu  2008-05-08 00:34:33 
Re: Overload resolution and copy constructors that take non-cons
James Kanze <james.kan  2008-05-09 03:28:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 15:42:56 CDT 2008.