TimeAlarms usage in a class function

Hi,
I get the following error if I use the Alarm.alarmRepeat(…) within a member function of a class declared within my sketch:

sketch_jan01a.ino: In member function ‘void Someclass::func()’:
sketch_jan01a:16: error: no matching function for call to ‘TimeAlarmsClass::alarmRepeat(int, int, int, <unresolved overloaded function type>)’
/home/agebee/arduino-1.0.5/libraries/TimeAlarms/TimeAlarms.h:69: note: candidates are: AlarmID_t TimeAlarmsClass::alarmRepeat(time_t, void (*)())
/home/agebee/arduino-1.0.5/libraries/TimeAlarms/TimeAlarms.h:70: note:                 AlarmID_t TimeAlarmsClass::alarmRepeat(int, int, int, void (*)())
/home/agebee/arduino-1.0.5/libraries/TimeAlarms/TimeAlarms.h:71: note:                 AlarmID_t TimeAlarmsClass::alarmRepeat(timeDayOfWeek_t, int, int, int, void (*)())

The sketch is here:

#include <Time.h>
#include <TimeAlarms.h>
      
class Someclass {

public:
  Someclass()
  {
    //ctor
  }
  void func()
  {
    Alarm.alarmRepeat(17,58,00,anotherFunc);
  }
  void anotherFunc()
  {
    Serial.println("anotherFunc");
  }
};

void setup() {
  Alarm.alarmRepeat(17,58,00,call);
}

void loop()
{
  delay(1000);
}
void call()
{
  Serial.println("call");
}

Using Alarm.alarmRepeat in the main part of my sketch works perfectly.

Do I need to tell Alarm the surrounding namespace ?
Thanks for your help.

Do I need to tell Alarm the surrounding namespace ?

No. You need to make the function that Alarm calls static. When the alarm goes off, the Alarm class has no idea which instance of your class it is to call a method for.

PaulS:

Do I need to tell Alarm the surrounding namespace ?

No. You need to make the function that Alarm calls static. When the alarm goes off, the Alarm class has no idea which instance of your class it is to call a method for.

Thanks a lot Paul, that helped. Let me put the reason for your solution in my words so everyone would have a take-away from that case:

If there were more intances of Someclass the program would not know to which instance the call of anotherFunc belongs to. Therefore the function is made static which has the effect that there is only one method belonging to every instance (if there were more). And now there is no doubt.

Correctly explained ?

Correctly explained ?

Almost. A static method belongs to the class, not the instances of the class. The class could have a static method that any instance could call, to say “Call me when the alarm goes off”. Each time an instance called that method, any previous instance’s request would be replaced with the current instance’s request. Then, when the alarm goes off, it would call the static method, and the class would then route the alarm to the correct instance.

Think of a hotel, with porters. Only one porter is on duty at a time. A porter is an instance of the BaggageHandler class. The doorman sees a customer arrives (like the alarm going off), and calls the BaggageHandler::handleBaggage() method. The BaggageHandler class looks to see which porter is on duty, and and dispatches that porter to handle the baggage, but invoking the porterOnDuty->toteThemBags() method. Obviously, the porterOnDuty pointer needs to be a class member (not static), so every porter knows whether he/she is on duty, or not. The BaggageHandler::ReportingForDuty(somePorter) (static) method would be called by a porter (BaggageHandler::ReportingForDuty(joe);), when the porter (joe) arrives for work, relieving any other porter of duty. The ReportingForDuty() method would assign the value of the porter on duty (joe) to the porterOnDuty member.

void loop()
{
  delay(1000);
}

I believe it should be:

void loop()
{
  Alarm.delay(1000);          // Wait 1000mS then start the LOOP again
}