g++: How RVO works in case that multiple translation units are involved
问题 Firstly please take a look at the following code, which consists of 2 translation units. --- foo.h --- class Foo { public: Foo(); Foo(const Foo& rhs); void print() const; private: std::string str_; }; Foo getFoo(); --- foo.cpp --- #include <iostream> Foo::Foo() : str_("hello") { std::cout << "Default Ctor" << std::endl; } Foo::Foo(const Foo& rhs) : str_(rhs.str_) { std::cout << "Copy Ctor" << std::endl; } void Foo:print() const { std::cout << "print [" << str_ << "]" << std:endl; } Foo getFoo