I've written a simplified version of my code, to illustrate my problem. In my program alot of other stuff is in the code, that's why I need to have some functions in a class. I don't know how to define the parameters so that the f2 of foo is finally called.
I can have f0 inside of testClass if it's the only way of solving the problem, but I don't know how to write that either.
#include <iostream>
using namespace std;
class testClass {
public:
void f1();
void f2(int i);
} foo;
void f0(void (*f)(int)) {
(*f)(1337); // f = a pointer to f2, which is sent from f1
}
void testClass::f2(int i) {
cout << i;
}
void testClass::f1() {
f0(&f2);
}
int i;
int main() {
foo.f1(); // I want foo.f1 to call f0 which should call foo.f2()
cin >> i;
}
If I were to remove both testClass:: and foo., it will work. But since I can't do that, how should I correctly define the parameter in f0? And how should I correctly call f0 inside of f1?
Please help!