Get result from array of member functions in c++

  arduino-c++, arduino-esp32, c++, esp32

This is a part of Arduino program(C++). MCU is ESP32.
I have defined a class. Inside it I have created an array of member functions.

class IRDN_Padidar_Zone
{
bool callAnimation();  
uint16_t Animate_None(enum_Effect inOut);
uint16_t Animate_Print(enum_Effect inOut);
uint16_t Animate_Print_Random(enum_Effect inOut);
uint16_t Animate_Print_Barfak(enum_Effect inOut);
uint16_t Animate_Print_Laser(enum_Effect inOut);
typedef  uint16_t (IRDN_Padidar_Zone::*animatFunction)(enum_Effect);
animatFunction animations[] = {&IRDN_Padidar_Zone::Animate_None,&IRDN_Padidar_Zone::Animate_Print,&IRDN_Padidar_Zone::Animate_Print_Random,&IRDN_Padidar_Zone::Animate_Print_Barfak,&IRDN_Padidar_Zone::Animate_Print_Laser};
};





bool IRDN_Padidar_Zone::callAnimation(enum_Effect state)
{
 uint16_t frameCounter = 0;
 frameCounter =  *animations[0](state);
 return true;
}

When I access this array in another class member function{callAnimation()}, I get the following error:

error: must use ‘.‘ or ‘->‘ to call pointer-to-member function in ‘animations[0] (…)’, e.g. ‘(… ->* animations[0]) (…)’
frameCounter = *animations0;

If id move typedefine and array of function, uotside of class like this:

class IRDN_Padidar_Zone
{
bool callAnimation();  
uint16_t Animate_None(enum_Effect inOut);
uint16_t Animate_Print(enum_Effect inOut);
uint16_t Animate_Print_Random(enum_Effect inOut);
uint16_t Animate_Print_Barfak(enum_Effect inOut);
uint16_t Animate_Print_Laser(enum_Effect inOut);
};

typedef  uint16_t (IRDN_Padidar_Zone::*animatFunction)(enum_Effect);
animatFunction animations[] = {&IRDN_Padidar_Zone::Animate_None,&IRDN_Padidar_Zone::Animate_Print,&IRDN_Padidar_Zone::Animate_Print_Random,&IRDN_Padidar_Zone::Animate_Print_Barfak,&IRDN_Padidar_Zone::Animate_Print_Laser};

Error change to:

error: too many initializers for ‘uint16_t (IRDN_Padidar_Zone::* [0])(enum_Effect) {aka short unsigned int (IRDN_Padidar_Zone::* [0])(enum_Effect)}’
Animate_From_Up,&IRDN_Padidar_Zone::Animate_From_Down,&IRDN_Padidar_Zone::Animate_From_UpDown,&IRDN_Padidar_Zone::Animate_Kerkerh,&IRDN_Padidar_Zone::Animate_Print_Rain};

I am confused.I an amateur in c++. Please help me.

Source: Windows Questions C++

LEAVE A COMMENT