我在类中声明了以下类型:
using ScriptFunction = std::function<void(std::string const&)>;
using Script_map = std::unordered_map<std::string, std::vector<ScriptFunction>>;
在这个类中,我希望存储其他类中的一些成员函数,并像这样调用它:
void Manager::callback(std::string event, std::string data) {
auto it = this->stored_func.find(event); //stored_func is a Script_map
for (auto func : it->second) {
func(data);
}
}
该代码有效,但是,我想更改它,以便可以回调接收1个或2个字符串或根本没有参数的函数。这可能吗?
可能对您有用的是带有可变参数的方法。与此类似。