When unique_ptr is replaced by shared_ptr everything works all right. Connection object can be shared between two DAO objects and we are assured that the pointer is deleted when it is not needed by any of the owners: