First of all, thank you in advance for your time.
Can I use a function pointer but when that function belongs to an object in a given class?
For example:
Code://// Example.h
#ifndef EXAMPLE_H_
#define EXAMPLE_H_
class Example {
public:
int funcA(int, int);
static int staticFuncB(int a, int b);
};
#endif
Code://// Example.cpp
#include "Example.h"
int Example::funcA(int a, int b) {
return a * b;
}
int Example::staticFuncB(int a, int b) {
return a * b;
}
Code://// Main.cpp
#include <stdio.h>
#include "Example.h"
int ejecutaFunc(int a, int b, int (*func)(int, int)) {
return (*func)(a, b);
}
int main() {
Example * a = new Example();
int resp1 = a->funcA(2, 3);
int resp2 = ejecutaFunc(2, 3, Example::staticFuncB); // Works
//int resp2 = ejecutaFunc(2, 3, a->funcA); // Failure
delete a;
return 0;
}
Is there any way to generate this behavior?
Thank youCode:int resp2 = ejecutaFunc(2, 3, a->funcA);

