I need to make a list of function pointers to member objects and then execute them as need be in an InterruptSubRoutine. I created a class with a virtual function to wrap all classes that need interrupts, and they will use to execute their interrupt.
I can pass these and put them in the Array, but I get an error on the line where I try to execute them saying
expression must have a (pointer-to-) function type.
Header
typedef bool (InterruptSubRoutine::*function_pointer)();
void initializeTI();
void enableTI();
void disableTI();
void procInterrupt();
void addInterrupt(bool (InterruptSubRoutine::*interrupt)());
TimerThree timerInt;
function_pointer activeInterrupts[INTERRUPT_POINTER_SIZE];
Cpp
void ::initializeTI()
{
timerInt.initialize(TIMER_INTERRUPT_PERIOD);
}
void ::procInterrupt()
{
bool empty = true;
for(int i = 0; i<INTERRUPT_POINTER_SIZE; i++)
{
if (activeInterrupts[i] != nullptr)
{
empty = false;
bool returnV = activeInterrupts[i](); //this is where i get the problem, with the error stating "expression must have a (pointer-to-) function type"
if (!returnV)
{
activeInterrupts[i] = nullptr;
}
}
}
if (empty)
{
disableTI();
}
}
void ::addInterrupt(bool (InterruptSubRoutine::*function)())
{
for(int i = 0; i<INTERRUPT_POINTER_SIZE; i++)
{
if (activeInterrupts[i] == nullptr)
{
activeInterrupts[i] = function;
break;
}
}
}
void ::enableTI()
{
void (*interrupt)(void);
interrupt = &procInterrupt;
timerInt.attachInterrupt(interrupt, TIMER_INTERRUPT_PERIOD);
}
void ::disableTI()
{
timerInt.detachInterrupt();
}