The following slides contrast patterns of "old school" and "modern" C++. http://klmr.me/slides/modern-cpp.pdf
Instead of writing
huge_object* build_new_object() {
huge_object* ret = new huge_object;
…
return ret;
}
they advise to write
huge_object build_new_object() {
huge_object ret;
…
return ret;
}
I understand that the first code snippet is bad because we have to remember to delete the huge_object, and it's not exception-safe.
But doesn't the second snippet have the disadvantage of leading to an expensive copy ctor call? Wouldn't return by smart pointer be much better than return by value?