So I've created an event driven architecture for my current program. I want each new event to have a number generated automatically with a function so I don't have to worry about overlap of id's and referencing is easy.
class Event
{
protected:
static int get_event_id();
public:
virtual int type() = 0;
};
class Event_Class
{
protected:
static int m_type;
char* msg;
int length;
public:
const char* get_msg();
int get_length();
int type(){return m_type;}
static void invoke(const char* msg);
//invoke this directly passes it to the event handler considering //renaming but that isn't a big deal
};
//seperate .cpp file
int counter = 0;
int Event::get_event_id()
{
return counter++;
}
Event_Class::m_type = Event::get_event_id();
Issues
1. "type" has to be defined as a static member with the name "type" (well technically no but I want the name to remain uniform, so that's why I find it bothersome) every time I inherit from the base event class. I'm not sure if there is another way to possibly fix this so it automatically makes a separate static int whenever I inherit from the base class with the same name. Each Event needs a different value, so declaring in the base class and inheriting isn't possible in any way I know.
The solution isn't near as elegant as it should be and I know there has to be a way to do something like this.