Pushing an object with unique_ptr into vector in C++
问题 I have a simple class structure modelling a discrete simulation, with a vector of States, which each contain a number of Transitions, held as a vector of smart pointers. I've used smart pointers to hold the transitions as in my full application I need polymorphism. #include <vector> #include <memory> class Transition { public: Transition() {} }; class State { public: State(int num) : num(num), transitions() {} void add_transition(std::unique_ptr<Transition> trans) { transitions.push_back(std: