I am trying to create an array of structs that contain pairs of Strings and Callbacks the problem I am having is assigning the callback function. I have the following code:
#define UI_ROUTINE_ITEMS 10
struct MenuItem{
String label;
typedef void (*callback)();
};
class MenuSystem{
MenuItem routineMenu[UI_ROUTINE_ITEMS];
MenuSystem(){
routineMenu[0] = {"Test", &Test::TestCallback};
}
}
class Test{
void TestCallback(){
Serial.println("Callback called");
}
}
When I try to compile this I get:
error: no match for 'operator=' (operand types are 'MenuItem' and '<brace-enclosed initializer list>')
I know this is a Syntax issue I just can not figure out how this should be done. I have looked at several examples but I can't figure out how to do this with Classes without using free/malloc, what am I doing wrong?
EDIT
I finally got this working, the problem was that the function that I was trying to call was not static and the declaration in the structure was not quite right. Below is the corrected example:
#define UI_ROUTINE_ITEMS 10
#include <Arduino.h>
struct MenuItem{
String label;
void (*callback)(void);
};
class MenuSystem{
MenuItem routineMenu[UI_ROUTINE_ITEMS];
MenuSystem(){
routineMenu[0] = {"Test", &Test::TestCallback};
}
}
class Test{
public static void TestCallback(){
Serial.println("Callback called");
}
}