Dereferencing a shared pointer and assigning to it
Dereferencing a shared pointer and assigning to it Is it ok to dereference a shared pointer, assign and assign a new object to it like so: void foo() { std::shared_ptr<std::string> x = std::make_shared<std::string>(); bar(*x); // is this fine? // x == bsl::string("WHATEVER") } void bar(string& y) { y = string("whatever"); } You are making changes to the object managed by the pointer ( you are not making it manage a new object) – M.M Jun 29 at 2:47 Yes, so the above code is safe then? I don't end up modifying a temporary or something like that? – Martin F Jun 29 at 2:51 Yes this is all fine ...
