Cannot-instantiate-abstract-class : timer Class

Hello All,
I have fooComponent class inheriting Timer,
fooComponent:: private Timer
{}

And I am using the fooComponent foo in MainComponent.h ,
I’m getting an error of fooComponent’: cannot instantiate abstract class

I’ve implemented the void timerCallBack() in both fooComponent and MainComponent
but not understanding where should I call startTimer(); in MainComponent

I checked the similar topic :Beginner error: "Cannot instantiate abstract class"
but I have to have fooComponent foo; as It is needed for other function calls.

Any suggestions/help is appreciated.
TIA!

You might have misspelled the function name in your code. It’s timerCallback.

The override keyword can help to avoid this sort of problem. If you always add override to overridden virtual functions, the compiler will inform you if it can’t find a suitable base class function to override.

@reuk Just checked, no typos in a code, infact it was here in the post!

if I use the keyword override there is C++ member function declared with 'override' does not override a base class member … in MainComponent

The error message is explaining the problem. There is no virtual function on the base class with a matching signature. Things to check:

  • Is the function name correct? (I know you checked, but this is most often the problem)
  • Do the function arguments match? (timerCallback() shouldn’t have any arguments)
  • Does the function return type match? (timerCallback() returns void)
  • Do all keywords on the function match? (timerCallback() should not have a trailing const)
  • Does MainComponent definitely derive from juce::Timer?

@reuk
To the last point, * Does MainComponent definitely derive from juce::Timer ?

MainComponent doesn’t, but fooComponent does which is included in MainComponent,

in other words, MainComponent has fooComponent object, and there only pops up the error

'xyz::fooComponent': cannot instantiate abstract class

OK, in that case you need to implement timerCallback on fooComponent rather than MainComponent.

@reuk Yes, I’ve implemented it in there.

Do I have to include them in MainComponent as well?

update: override keyword in fooComponent was missing, adding that fixed the problem

Thank you!