why visual studio does not optimize constructor in this case
Hello everyone,
Why visual studio does not optimize constructor in this case? I do not understand what the MSDN mentioned,
if use different named object, compiler can not optimize. Why?
http://msdn2.microsoft.com/en-us/lib...57(vs.80).aspx
Code:
#include <stdio.h>
class RVO
{
public:
RVO(){printf("I am in constructor\n");}
RVO (const RVO& c_RVO) {printf ("I am in copy constructor\n");}
int mem_var;
};
RVO MyMethod (int i)
{
RVO rvo;
rvo.mem_var = i;
if (rvo.mem_var == 10)
return (RVO());
return (rvo);
}
int main()
{
RVO rvo;
rvo=MyMethod(5);
}
Output is,
I am in constructor
I am in constructor
I am in copy constructor
My expected output is,
I am in constructor
I am in constructor
thanks in advance,
George