struct String
{
String()
{
std::cout<<"String::String(), this="<<this<<std::endl;
}
~String()
{
std::cout<<"String::~String(), this="<<this<<std::endl;
}
String(String const &other)
{
std::cout<<"String::String(String const &other), this="<<this;
std::cout<<", other="<<&other<<std::endl;
}
String& operator=(String const &other)
{
std::cout<<"String::operator=(String const &other), this="<<this;
std::cout<<", other="<<&other<<std::endl;
return *this;
}
};
String const operator*(String const &lhs, String const &rhs)
{
String temp(rhs);
std::cout<<"return by value(* operator)"<<std::endl;
return temp; //without copy construct
}
int main()
{
std::cout<<"***************value******************"<<std::endl;
String D;
String E;
String F;
D = E * F;
std::cout<<"***************value******************"<<std::endl<<std::endl;
std::cin.get();
return 0;
}
Compiler vc2010
OS win7 64bits
I expected it would copy construct temp before calling copy assignment
What kind of optimization did it done?NRVO?
If NRVO did it, what is the limit of NRVO?
Thanks