<unresolved overloaded function type>

Hi,

I don’t get the code below working (except with the wrapper function). I do not want to use the wrapper function because it kills the function callback idea. How can I write the code without writing the wrapper function? Hope you can help me, thx.

This is the code that gives the error:

#include <TimedAction.h>
#include <Time.h>
#include <TimeAlarms.h>

const unsigned long timeout10Sec = 10000; //10 sec.

TimedAction boilerTimeout = TimedAction(timeout10Sec, boilerPowerOff);

void boilerPowerOff(){
  //power off te boiler.
}

void setup(){
  setTime(8,29,0,1,1,10); // set time to 8:29:00am Jan 1 2010
  // create the alarms
  Alarm.alarmRepeat(8,30,0, boilerTimeout.reset);
}

void loop(){
  boilerTimeout.check();
}

I receive this error message:

error_example.cpp: In function 'void setup()':
error_example:19: error: no matching function for call to 'TimeAlarmsClass::alarmRepeat(int, int, int, <unresolved overloaded function type>)'
C:\Users\athome\Dropbox\Home automation\Arduino\arduino-0022\libraries\TimeAlarms/TimeAlarms.h:69: note: candidates are: AlarmID_t TimeAlarmsClass::alarmRepeat(time_t, void (*)())
C:\Users\athome\Dropbox\Home automation\Arduino\arduino-0022\libraries\TimeAlarms/TimeAlarms.h:70: note:                 AlarmID_t TimeAlarmsClass::alarmRepeat(int, int, int, void (*)())
C:\Users\athome\Dropbox\Home automation\Arduino\arduino-0022\libraries\TimeAlarms/TimeAlarms.h:71: note:                 AlarmID_t TimeAlarmsClass::alarmRepeat(timeDayOfWeek_t, int, int, int, void (*)())

This is the code with the wrapper function which works fine:

#include <TimedAction.h>
#include <Time.h>
#include <TimeAlarms.h>

const unsigned long timeout10Sec = 10000; //10 sec.

TimedAction boilerTimeout = TimedAction(timeout10Sec, boilerPowerOff);

void boilerPowerOff(){
  //power off te boiler.
}

void wrapper(){
  boilerTimeout.reset();
}

void setup(){
  setTime(8,29,0,1,1,10); // set time to 8:29:00am Jan 1 2010
  // create the alarms
  Alarm.alarmRepeat(8,30,0, wrapper);
}

void loop(){
  boilerTimeout.check();
}

I think a typecast will sort this out, case the boilerTimeout.reset to the right function type.

But what is the correct typecast? The callback is defined as a simple void.

void (*OnTick_t)()

I just don't get it right :(.

Unfortunately, the wrapper is the way to go. Your function boilerTimeout.reset() is a member function of an object - what is implied in an object is that there is a pointer to the object (called 'this') that is passed through. C++ hides the pointer in many cases from view, but that means that the actual function here is not

void boilersomething::reset()

but (very, very roughly)

void boilersomething::reset(void*thisPtr)

So you can see why the function fails, and why you need the wrapper. If the function was not an object class member function, or was static, you'd be fine.

Thx David, that is the problem :).

I found a very good in-depth explanation of the problem here: http://www.newty.de/fpt/callback.html#static