unique_ptr and polymorphism
问题 I have some code that currently uses raw pointers, and I want to change to smart pointers. This helps cleanup the code in various ways. Anyway, I have factory methods that return objects and its the caller's responsibility to manager them. Ownership isn't shared and so I figure unique_ptr would be suitable. The objects I return generally all derive from a single base class, Object . For example, class Object { ... }; class Number : public Object { ... }; class String : public Object { ... };