jeudi 11 mars 2021

why using std::move and assign to rvalue does not steal internal content?

As is known to all that c++ std::move would steal internal content if used with non-fundamental type. I suddenly have a brainwave that what will happen to rvalue if move a lvalue to it. I initially thought it would still steal the content. But nothing happened,a has its string still. Does this caused by ignoring the move constructor? But I think a named rvalue is deemded by compiler to be lvalue, right?

int main()
{
    string a="4";
    string&& c = move(a);
    cout<<a<<endl;
}

Aucun commentaire:

Enregistrer un commentaire