Please consider the three functions.
std::string get_a_string()
{
return "hello";
}
std::string get_a_string1()
{
return std::string("hello");
}
std::string get_a_string2()
{
std::string str("hello");
return str;
}
- Will RVO be applied in all the three cases?
- Is it OK to return a temporary like in the above code? I believe it is OK since I am returning it by value rather than returning any reference to it.
Any thoughts?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…