Objectif of this code is to create a wrap around diffent template design (an implementation with always the same handler work), but with this try I have the following error "error: request for member 'pushEvent' is ambiguous" I don't understand (detail of the error on the bottom of the message)
template<typename T>
struct EventHandler {
EventHandler() {}
inline void pushEvent(T & msg) {
printf("pushEvent %s", typeid(T).name());
q_.push(msg);
}
protected:
std::queue<T> q_;
};
The wrapper of deferend template (some method will be add to handle the different type of events
template<typename... EventHandler>
struct _EventsHandler : EventHandler... {
};
// usage sample : We create the type that will instantiate the event manager
using EventHandlerType = EventsHandler<EventHandler<int>,EventHandler<float>,EventHandler<char>>;
int main(void) {
EventHandlerType test;
int msp = 1;
test.pushEvent(msp);
}
I don't understand the ambiguous error as msp type is int and should give information to solve the ambiguity ?
error: request for member 'pushEvent' is ambiguous
test.pushEvent(msp);
^
note: candidates are: void _EventHandler<T>::pushEvent(T&) [with T = char]
inline void pushEvent(T & msg) {
^
note: void _EventHandler<T>::pushEvent(T&) [with T = float]
note: void _EventHandler<T>::pushEvent(T&) [with T = int]
note: void _EventHandler<T>::pushEvent(T&) [with T = char]
I know that such solution can be handled differently, but I want to understand the WHY of this error, so please don't mark this question as "already answered" if the answer is "there is an other way to solve your problem"