dimanche 16 août 2020

constructor with std::move without passing by reference

I sometimes encounter the following type of constructor.

struct A
{
    std::string a; 
    A( std::string a ) : a( std::move(a) ){ }  \\ a is not passed by reference
};

Something confusing to me is that, it seems that a is not passed by the reference, thus a copy of a is made. And if so, this is nonsense to do std::move. But many experts seem to do this, so there must be reason behind that. Could you explain why?

Aucun commentaire:

Enregistrer un commentaire