I'm trying to understand rvalue
references. I have seen how they are used in constructors, with things like std::move
and std::forward
, but I still don't understand why this doesn't work:
void func(string&& str)
{
cout << str << endl;
}
int main(int argc, char* argv[])
{
string s("string");
func(s);
}
And this does:
template<typename T>
void func(T&& str)
{
cout << str << endl;
}
int main(int argc, char* argv[])
{
string s("string");
func(s);
}
Why does it work with the function template version?