I looked at a few smart pointers, but they don't really look like reducing complexity or things to care for. Am I misunderstanding smart pointers?
Probably yes. In C ++, since you have to deal with it yourself (GC will not clear it for you), you need a way to track the usage of each object.
You can manually map each new to delete , but it is sometimes difficult or impossible, for example, in your script above. It is not possible to find out if this object is being used elsewhere.
Smart pointers solve this by managing the lifetime for you, so you don't need to delete. They use various mechanisms to track the number of places the object is used, and call delete when the last one is executed.
However, in this particular case there are not many reasons to use pointers. If you work with std::string , you can pass a string by value, and that will never be a problem.
source share