A doubt about Timer in M.I

Hi community,

This one is more related to C++ language rather than Juce. I am not able to resolve the ambiguity in this case:


class Timer
{
public:
    void startTimer(int) {}
};
class B : public Timer
{
public:
    ...
};
class C : public B, public Timer
{
    void cfunc(void)
    {
        B::startTimer( 30 );
        A::startTimer( 50 );
    }
};


B::startTimer( 30 ) is resolved neatly, but the compiler is noat able to resolve A::starTimer( 50 ).

Please, how can I reach A::startTimer()?

 

Thank you in advance,

Gabriel

http://www.parashift.com/c++-faq/mi-disciplines.html

 

You often don’t want to use the same timer callback in B and C.
I once worked around this with a helper object as timer:


class ExternalTimer : public Timer, public ChangeBroadcaster
{
public:
  timerCallback() { sendChangeMessage(); }
};


class C : public B, public ChangeListener
{
public:
  C() { extTimer.startTimer(1000); }
  
void changeListenerCallback(ChangeBroadcaster* source) 
{
  if (source == &extTimer)
    internalTimerCallback()
}
private:
  void internalTimerCallback()
  {
    // This classes timer callback
  }

  ExternalTimer extTimer;
}

Although it works, it isn’t the cleanest solution as there’s a delay plus additional messaging due to the ChangeBroadcaster.

Chris

Also have a look at Button::RepeatTimer, or MouseDragAutoRepeater, JucerTreeViewBase::ItemSelectionTimer etc.

With C++11 this stuff will all be avoidable by using lambdas, but until then I think the trick is just to avoid complicated inheritance patterns unless it's genuinely essential (which is rare).

Thank you!