Replacing the content of the shared pointer?
boost, c++, shared-ptr
Solution
If I understood you correctly - you could use overloaded dereference operator:
auto a = std::make_shared<int>(42);
auto b = a;
*a = 43;
std::cout << *b << std::endl;
Output:
43
Problem
I have a shared pointer that I have shared around the system. Later on, I want to replace the actual content of these shared pointers point to, but still keep all the shared pointers valid, so they internally point to this new object. Is there an easy way to do this with shared pointers? Kind of like this I am looking for - pseudo-code ``` typedef boost::shared_ptr<Model> ModelPtr ModelPtr model1 = ModelPtr(new Model); ModelPtr model2 = model1; // make something like 'model1.get() = new Model' so model1, model2 both points to a new model ``` EDIT: I want the effect of this, but less gimicky ``` ModelPtr model1 = ModelPtr(new Model("monkey")); memcpy(model1 .get(), new Model("donkey"), sizeof(Model)); ```