我有基于插件的体系结构,其中有工厂类:
darknet53.conv.74
我想实现class PluginFactory {
public:
std::shared_ptr<Plugin> GetPlugin(PluginType type);
private:
static std::map<PluginType, std::shared_ptr<Plugin>> plugin_map_;
};
,它将实例添加到Register(type)
。我想从每个plugin_file调用宏map
,该宏将调用REGISTER_PLUGIN()
。如何在C ++中做到这一点?
答案 0 :(得分:2)
这称为“自动注册工厂”模式。
您可以在此处找到文章:C++ Tutorial: Auto Registering Factory
一如既往,请谨慎使用。只需在中心位置手动注册类型就足够了,并且可以省去很多麻烦。