1

I know, many post asking about this, been reading about 10 post with long answers but, every post seems different case and needs different implementation.

so, what did i do wrong here?

#include <iostream>
using namespace std;
class Foo {
   public:
    void callbackFunc(void (*funcParam1)());
    void funcA();

};
void Foo::callbackFunc(void (*funcParam1)()) {
    funcParam1();
}
void Foo::funcA() { cout << "func A OK.." << endl; }
void aa(){
    int x =0;
}
Foo bar;
int main() { bar.callbackFunc(bar.funcA); }


this example throws error: invalid use of non-static member function ‘void Foo::funcA()’ in the main() especially in the callbackFuncparameter.

i want to use it in arduino later.

Jastria Rahmat
  • 776
  • 1
  • 6
  • 27

1 Answers1

2

You may get away with the error with static funcA:

static void funcA();

Looks like the problem is that your callbackFunc expects a function pointer, but member function funcA is not a normal function and expects an object to begin with. Making it static would get away of the issue.

artm
  • 17,291
  • 6
  • 38
  • 54
  • hi, this partially correct. but, later on, each instance will utilize variables from each class. So, making it static won't solve the problem. But, thank you for the answer. – Jastria Rahmat Mar 31 '20 at 08:36