I've got the following code for my event manager:
#pragma once
namespace EventManager {
enum class EventType {
OnUpdate,
OnDraw,
Size
};
extern std::vector<void*> EventCallbacks[(unsigned int)EventType::Size];
void AddEventHandler(EventType eventId, void* callback);
void RemoveEventHandler(EventType eventId, void* callback);
template <typename... Args>
void Trigger(EventType eventId, Args... args) {
for (auto callback : EventCallbacks[(unsigned int)eventId]) {
static_cast<void(*)(Args...)>(callback)(args...);
}
}
template <typename... Args>
bool TriggerProcess(EventType eventId, Args... args) {
auto process = true;
for (auto callback : EventCallbacks[(unsigned int)eventId]) {
if (!static_cast<bool(*)(Args...)>(callback)(args...)) {
process = false;
}
}
return process;
}
}
And I'm trying to call EventManager::AddEventHandler from inside another class, but I'm getting the following error:
It works fine if I try to do that from a namespace instead of class, but I can't seem to figure out how to make it work from inside this class.