c++ - Move semantics and virtual methods -
in c++11 guided in cases pass objects value , in others const-reference. however, guideline depends on implementation of method, not on interface , intended usage clients. when write interface, not know how implemented. there rule of thumb writing method signatures? example - in following code fragment, should use bar1 or bar2 ? class ifoo { public: virtual void bar1(std::string s) = 0; virtual void bar2(const std::string& s) = 0; }; you can stop reading here if agree correct signature depends on implementation. here example shows why believe so. in following example, should pass string value: class foo { std::string bar; foo(std::string byvalue) : bar(std::move(byvalue)) { } }; now can instantiate foo in efficient manner in cases: foo foo1("hello world"); // create once, move once foo foo2(s); // programmer wants copy s. 1 copy , 1 move foo foo3(std::move(t)); // programmer not need t anymore. no copy @ in other case