You just reassign or reset it.
Example:
#include <iostream>
#include <memory>
template<typename T>
std::shared_ptr<T> func(std::shared_ptr<T> m)
{
m = std::make_shared<T>(T{});
return m;
}
int main(){
std::shared_ptr<int> sp1 = std::make_shared<int>(44);
auto sp2 = func(sp1);
std::cout << *sp1 << '\n' << *sp2 << std::endl;
}
source
share