I have a class A object created inside a method. This method also creates an instance of object B , which takes the newly created object A as a constructor argument. B must take responsibility for object A , but he cannot change it. This means that A should be deleted when B is removed, but during the life of B it cannot change A
In this case, a std::unique_ptr<const A> as a member variable of B is the right way to transfer ownership of A (using std::move in constructor B ) and ensure that it will not be changed?
source share