首页 > 试题广场 >

以下代码使用了std::move和const引用,会发生什么

[单选题]
以下代码使用了std::move和const引用,会发生什么?
#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
  • 编译错误
  • 未定义行为

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