#include #include #include struct OpInterface { std::string _name; OpInterface(std::string name) : _name(name) {} virtual void operator()() = 0; virtual ~OpInterface() {} }; struct OpA : public OpInterface { OpA(std::string name) : OpInterface(name) {} void operator()(){std::cout << _name << std::endl;} }; struct OpB : public OpInterface { OpB(std::string name, std::string suffix) : OpInterface(name+suffix) {} void operator()(){std::cout << _name << std::endl;} }; int main(int /*argc*/, char** /*argv*/) { // Forge container using indices. eoForgeVector indexed_factories; // Capture constructor's parameters and defer instantiation. indexed_factories.add("I'm A"); indexed_factories.setup(0, "I'm actually A"); // Edit indexed_factories.add("I'm B", " prime"); indexed_factories.add("I'm a B", " junior"); // Actually instantiante and call. indexed_factories.instantiate(0)(); indexed_factories.instantiate(1)(); indexed_factories.instantiate(2)(); }