我当前正在尝试为引擎创建事件模板类。
我的事件类有一个std::Vector<T>
,其中t
将被定义为指向需要该事件的函数的指针。
[调用事件时,它将调用带有必需参数的添加到向量的每个函数。
问题在于尝试编译此部分代码以调用事件。
此刻它是这样写的。
template <typename... Args>
void Call(Args ... args)
{
for (T f : functions)
{
f->*(args...);
}
}
注意,我已经尝试过了:
f->*((args),...);
f->*(std::forward(args)...);
f->*(args)...;
和许多其他类似的解决方案。
每次我尝试编译我的代码时都会遇到:
**include/event.h:71:22: error: expected ‘)’ before ‘...’ token
f->*(args...);
^
include/event.h:71:26: error: parameter packs not expanded with ‘...’:
f->*(args...);**
我真的不明白这里的问题。
感谢您的帮助!
如果可以访问c++17,请使用std::invoke