1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #include <string> #include <utility>
struct A { A(std::string str) : str_(std::move(str)) {} std::string str_; };
struct B { B(const std::string& str) : str_(str) {} std::string str_; };
int main() { std::string str = "hello"; A a1(str); A a2(std::move(str));
std::string str2 = "hello"; B b1(str2); B b2(std::move(str2)); }
|