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