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 7 of 11 Topic 45791 of 47032
Post > Topic >>

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

by dizzy <dizzy@[EMAIL PROTECTED] > May 7, 2008 at 05:47 PM

Victor Bazarov wrote:

> Branimir Maksimovic wrote:
>> On May 7, 3:21 pm, Branimir Maksimovic <bm...@[EMAIL PROTECTED]
> wrote:
>>> What about
>>> A foo()
>>> {
>>> A a;
>>> return a;}
>>>
>>> A a;
>>> a = foo();
>>> Is compiler obliged to call copy constructor?
>>
>> Err, I mean to construct tem****ary.
> 
> Yes, with assignment it would have to create a tem****ary (and BTW
> I really hope the 'a = foo();' statement is inside some function
> otherwise it would be ill-formed).  There are no provisions in the
> Standard to allow skipping creating a tem****ary when one would be
> required because the expression on the right-hand side of the
> assignment operator produces it.  The creation of the tem****ary
> is only allowed to be skipped in the case of initialising an object
> of the same type:
> 
>     A a = foo();

I think there was one more case where copy ctor elusion is permited. I
would
also like to add that this is special treatement in the standard for these
cases even if the copy ctor has observable behaviour altering code.
Because
in general if calling or not calling the copy ctor results in the same
observable behaviour (which is to be expected to most copy ctors that
usually don't have side effects) then the compiler can optimize out the
call anyway no matter of being in such a special case or not :)

-- 
Dizzy
 




 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 21:11:47 CDT 2008.