Mihai
Mihai

Reputation: 1084

Call matching methods from inherited classes

what is the best method to call matching methods from a single class that inherit 3 other base classes with same method name? i want to call those methods from a single call, don't know if it's even possible

template<typename T>
class fooBase()
{
    void on1msTimer();
    /* other methods that make usage of the template */
}

class foo
    : public fooBase<uint8_t>
    , public fooBase<uint16_t>
    , public fooBase<float>
{
    void onTimer()
    {
         // here i want to call the on1msTimer() method from each base class inherited 
         // but preferably without explicitly calling on1msTimer method for each base class
    }
}

Is there any way to do this? Thanks

Upvotes: 1

Views: 58

Answers (1)

Christophe
Christophe

Reputation: 73366

It is not possible with one call to get all the three member functions at once. Imagine these member functions would return something else than void: which return value would you expect ?!

If you want to call the on1msTimer() of all the three base classes, you need to call these explicitly:

void onTimer()
{
     fooBase<float>::on1msTimer();
     fooBase<uint8_t>::on1msTimer();
     fooBase<uint16_t>::on1msTimer();
}

Online demo

Upvotes: 3

Related Questions