ISSUE
When i am iterating through an array of pointers to functions i am always getting an error in this example case of code. But if i wont iterate through them everything work fine as it ca be seen by the code below too.
Code
class OutterClass {
private:
class InnerClass{
public:
InnerClass(){}
float Func1 (const float &x ) { return (x > 0) ? x : 0 ;}
float Func2 (const float &x ) { return 1 / (1 + exp(-x)) ;}
float Func3 (const float &x ) { return (x > 0) ? x : (exp(x) - 1) ;}
void test_ISSUE(){
//this doesn't work
/*
for(int i=0; i<3; i++)
Serial.println(((this)->*(Function_ptrs)[i])(2));
*/
// this works
Serial.println(((this)->*(Function_ptrs)[0])(2));
Serial.println(((this)->*(Function_ptrs)[1])(2));
Serial.println(((this)->*(Function_ptrs)[2])(2));
}
};
typedef float (InnerClass::*method_function) (const float &);
static const method_function (Function_ptrs)[3] = {
&InnerClass::Func1,
&InnerClass::Func2,
&InnerClass::Func3
};
public:
InnerClass *Reference;
OutterClass(){ Reference = new InnerClass();}
};
void setup() {
Serial.begin(9600);
OutterClass *Obj = new OutterClass();
Obj->Reference->test_ISSUE();
}
void loop () {}
Recreating the Error
just uncomment for(int i=0; i<3; i++) ...
Error
...: In function `test_ISSUE':
.../sketch_jan23a.ino:17: undefined reference to `OutterClass::Function_ptrs'
.../sketch_jan23a.ino:17: undefined reference to `OutterClass::Function_ptrs'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.
Any idea?
UPDATE SOLUTION
just used inline static const method_function (Function_ptrs)[3]
as stated here and now it works..