Is there anyone who can help explain why UseString
in my following example cannot accept an lvalue as a parameter? I know a temporary String
is created in my case, but I cannot explain why it has to accept an rvalue here.
#include <utility>
using namespace std;
struct String
{
String(const char* cstr)
{
}
};
struct UseString
{
UseString(const String& str)
{
}
};
int main()
{
const char* cstr = "abc";
UseString(std::move(cstr)); //Correct
UseString("abc"); // Correct
UseString(cstr); // Error but why UseString cannot accept lvalue as parameter in this case?
return 0;
}