#include <string>
#include <iostream>
void process(const std::string& s) { std::cout << "copy "; }
void process(std::string&& s) { std::cout << "move "; }
int main() {
const std::string s = "hello";
process(std::move(s));
} #include <string>
#include <iostream>
void process(const std::string& s) { std::cout << "copy "; }
void process(std::string&& s) { std::cout << "move "; }
int main() {
const std::string s = "hello";
process(std::move(s));
} 输出 move
输出 copy
编译错误
未定义行为

这道题你会答吗?花几分钟告诉大家答案吧!