dimanche 22 novembre 2020

Why m_ptr = nullptr should be done after moving the data (stealing the data ) with move constructor in C++ 11?

After using a Move constructor in c++11, Whats the purpose of reset the pointer of the rvalue that we already steal I Mean why do we assign a nullptr to the Old Object after Stealing its content? Is it to avoid duplication of the pointer?

Auto_ptr2(Auto_ptr2& a) // note: not const { m_ptr = a.m_ptr; // transfer our dumb pointer from the source to our local object a.m_ptr = nullptr; // make sure the source no longer owns the pointer }

Aucun commentaire:

Enregistrer un commentaire