如下代码,为何调用的是第一个版本的reference函数?编译器是按照什么规则来选择重载函数?
#include <iostream>
#include <string>
void reference(std::string& str) {
std::cout << "lvalue" << std::endl;
}
void reference(std::string&& str) {
std::cout << "rvalue" << std::endl;
}
int main()
{
std::string lv1 = "string,";
std::string&& rv2 = lv1 + lv2;
reference(rv2); // output: lvalue
return 0;
}
--
FROM 114.253.34.*