Suppose I want to have different handlers for different kind of messages, each message is identified by an int
. I want to define each handler as an instantiation of a template method.
The idea is something like this:
handlers.h
enum Handler {
MESSAGE1,
MESSAGE2
};
template<MESSAGE1>
void handle() {
}
main.cpp
int main()
{
handle<Handler::MESSAGE>();
}
Of course this code does not compile because MESSAGE1
is not a type.
So, how could I create a different type for each message ? Also, I'd like to maintain the use of these types as meaningful as possible (hence the use of enums).