Gaetano, the owner of cpp-today blog (see the link on the right) read my previous post and explain me that a constructor like T(T&) is the base of the "Move Constructor Idiom"
The programmer that wrote the (horrible) code of the previous post hasn't thinking about that, he just don't know the correct prototype of a copy constructor, but I didn't know anything about that move constructor so I read something about
This idiom comes out when there-s the need of "move semantic". In practice we want to "copy" an object modifying the one passed as parameter. The main example of a class that need a move constructor is std::auto_ptr.
You can read more here
Then, it a good practice to pay attention on constructor declarations, to avoid undesirable behaviors
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment