我在 VS2017 和 g++ 上都收到此错误,编译符合 C++17。谁能解释一下?
template<typename T>
T doit(T&& arg) {
int result{ arg * 2 };
return result; // works
// return arg; // works
// return arg*2; // error: C2440 'return': cannot convert from 'int' to T
}
int main() {
int i {42};
cout << doit(i) << endl;
return 0;
}