0

This code is just a way to experiment the variadic template possibilities.

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 knwo 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"

O'Neil
  • 3,705
  • 3
  • 14
  • 29
zadigus
  • 23
  • 5
  • 1
    For first, don't use underscore followed by capital letter this style is reserved for STL use. – 101010 May 30 '14 at 11:47
  • I agree (and correct the sample), I just use this trick to rename my code removing element to provide easy to read code, _ is not used in the real code – zadigus May 30 '14 at 11:52
  • The templates are irrelevant to your problem. The same behavior happens and is expected with normal multiple inheritance. – pmr May 30 '14 at 11:55
  • I knwo 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" – zadigus May 30 '14 at 12:02
  • @user3691084 The question I linked gives a very detailed explanation of the **why** including quotes from the standard. What more do you want? – pmr May 30 '14 at 16:59
  • @pmr Sorry I didn't understand your comment, I think first you suggest me to look for an over method only. – zadigus May 30 '14 at 20:41

0 Answers0