即使使用…,参数包也不会以'...'扩展

问题描述 投票:0回答:1

我当前正在尝试为引擎创建事件模板类。

我的事件类有一个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++ templates events function-pointers args
1个回答
0
投票

如果可以访问,请使用std::invoke

© www.soinside.com 2019 - 2024. All rights reserved.