I'm using the new version of the compiler and decided to try out the variadic templates functionality to make an event class:
template<typename... $arguments>
class Event
{
public:
std::vector<void (*)($arguments...)> Handlers;
public:
Event();
~Event();
void Attach(void (*callback)($arguments...));
void Detach(void (*callback)($arguments...));
void DetachAll();
void operator()();
flow IsHandled() const;
};
This is what it looks like, but when I use it in main.cpp:
void TestFunc(int arg, float arg2)
{
system("pause");
}
Event<int, float> evt;
evt.Attach(TestFunc);
evt();
It tells me "Error 1 error C2198: 'void (__cdecl *)(int,float)' : too few arguments for call"
This is what should happen when it's called:
template<typename... $arguments>
void Event<$arguments...>::operator()()
{
for(inti = 0; i < Handlers.size(); i++)
{
(Handlers)[i]();
}
}
I also tried with (Handlers)($arguments...) and also (Handlers)(...$arguments) and (Handlers)($arguments), and it changes nothing, it still tells me too few arguments.Does anyone have experience with variadics?