I have a class A which has a field of type std::unique_ptr:
class A
{
public:
std::unique_ptr pointer;
// class body
};
And somewhere in code, I'm using few std::shared_ptrs which point to the same object. Now what I'd like to achieve is to move ownership to this std::unique_ptr in my class, so that if all shared_ptrs will be destroyed, my object will stay alive as long as this unique_ptr will stay alive.
My question is - is it possible to move ownership from std::shared_ptr to std::unique_ptr and if yes, how can I do this?
shared_ptralives; if that is the case, then you can still useshared_ptras member ofAand pretend that it isunique_ptr.shared_ptrdoesn't providereleasemethod for a reason.std::weak_ptr. If so, then make sure you use onestd::shared_ptrand all others asstd::weak_ptr.