I am working on a project and want to attack a callback function to a ticker. I am using the ESP8266 Ticker library. In the following code snippet I pasted the relevant parts of the Ticker library just to reproduce the error. You would get the same error if you remove the Ticker class and include the Ticker.h.
class Ticker
{
public:
typedef void (*callback_t)(void);
void attach(float seconds, callback_t callback);
};
class Effect
{
public:
Effect()
{
ticker.attach(10, tick);
}
Ticker ticker;
typedef void (*callback_t)(void);
callback_t tick();
};
void setup() {}
void loop() {}
I get the following error when compiling:
[...]\sketch_may10b.ino: In constructor 'Effect::Effect()':
sketch_may10b:13: error: no matching function for call to 'Ticker::attach(int, <unresolved overloaded function type>)'
ticker.attach(10, tick);
^
[...]\sketch_may10b.ino:13:29: note: candidate is:
[...]\sketch_may10b.ino:5:10: note: void Ticker::attach(float, Ticker::callback_t)
void attach(float seconds, callback_t callback);
^
[...]\sketch_may10b.ino:5:10: note: no known conversion for argument 2 from '<unresolved overloaded function type>' to 'Ticker::callback_t {aka void (*)()}'
exit status 1
no matching function for call to 'Ticker::attach(int, <unresolved overloaded function type>)'
I think this is weird because I pass tick of type callback_t to the attack method so it should match, right? I am clueless as to what is going on here and would be very happy if you could lead me in the right direction here.
The weird thing to me is: When I do this whole thing outside of classes I can just declare tick() of type void and the attack method takes it without a problem. I don't understand the difference in this case between doing the same thing in and outside of a class.
Thanks a ton!