I have a optional property event that I define as a pointer in this struct:
struct AnimatedSprite {
//...some other properties
Event *event;
};
Let's say I want to store a StartTransitionEvent , defined like this:
class Event {
public:
Event() = default;
};
class StartTransitionEvent: public Event {
public:
int test = 1;
};
I can create and assign the StartTransitionEvent:
auto sprite = AnimatedSprite{};
auto newEvent = StartTransitionEvent{};
sprite.event = &newEvent;
But how do I get the type once I need to call something like:
eventBus->EmitEvent<StartTransitionEvent>(sprite->event);
Should I do some sort of checking on my event pointer to get to the StartTransitionEvent? Or maybe not use pointers at all and go for a std::variant to store the event with all it's possible child-classes?