I have a base class which I am passing with unique_ptr as a reference to a function and I want to copy/move it to a derived class shared_ptr (or unique_ptr what I want it is too guarantee no memory leaked throughout the execution).
I am doing this:
std::shared_ptr<Derived> f(unique_ptr<Base>& b_ptr){
std::shared_ptr<Derived> d_ptr= std::make_shared<Base>(std::move(b_ptr));
return d_ptr;
}
This is what I would like to have, but I know that this is not the right way, I would like to know how could I do something like this.