Quick A: It prevents you of being able to move your class.
Recently on SO:
Marking std::unique_ptr class member as const
Because of the nature of a
std::unique_ptr(sole ownership of an object) it's required to have no copy constructor whatsoever. The move constructor(6) only takes non-const rvalue-references which means that if you'd try to make your_childconstand move it you'd get a nice compilation errorEven if a custom
unique_ptrwould take a const rvalue-reference it would be impossible to implement.

Add a Comment
Comments are closed.