R
Rahul
While reading "Efficient C++" by Dov Bulka I came across the follown
statement
"In addition, you must also define a copy constructor to "turn on" the
Return Value Optimization(RVO). If the
class involved does not have a copy constructor defined, the RVO is
quietly turned off."
I searched a lot on the groups but still could not find any
satisfactory answer which explains this.
My doubt is "Even if we don't define a copy constructor then compiler
defines one automatically for us". So in this case also compiler
should do optimization. Then why does the book says "you must define"
I know if copy constructor is provate then you can not write
statements like
Complex c = c1+ c1;
which means compiler has no oppertunity to apply RVO.
But I am confused with the case when "we have compiler provided copy
constructor". When i checked with VC++ 7 then it did RVO with the
compiler generated copy constructor also.
Please let me know if i mis-interperted the book's statement, or
please explain me the above case.
Regards
statement
"In addition, you must also define a copy constructor to "turn on" the
Return Value Optimization(RVO). If the
class involved does not have a copy constructor defined, the RVO is
quietly turned off."
I searched a lot on the groups but still could not find any
satisfactory answer which explains this.
My doubt is "Even if we don't define a copy constructor then compiler
defines one automatically for us". So in this case also compiler
should do optimization. Then why does the book says "you must define"
I know if copy constructor is provate then you can not write
statements like
Complex c = c1+ c1;
which means compiler has no oppertunity to apply RVO.
But I am confused with the case when "we have compiler provided copy
constructor". When i checked with VC++ 7 then it did RVO with the
compiler generated copy constructor also.
Please let me know if i mis-interperted the book's statement, or
please explain me the above case.
Regards