0
I need to pass as a parameter to a member function another member function (but of another class). I can do this for same class functions, but from another
#include <iostream>
using namespace std;
void MyP(int a) {
cout << a << endl;
}
class MyPrint {
public:
void MyP(int a) {
cout << a << endl;
}
};
class MyClass {
public:
void MyC(void (*Op)(int)) {
Op(4);
}
};
int main() {
MyPrint A;
MyClass P;
P.MyC(MyP); // Funciona -> Pega a função normal (sem a classe)
P.MyC(A.MyP); // Não Funciona -> Pega a função membro (da classe)
getchar();
return 0;
}
Thanks.
The problem is that the method
MyPofMyPrintis an instance method, so you need the reference to the object. If you make it static you will see that it works.– Isac
I found a solution that can call non-static functions within the friend class. I put it hereCall Ticker library from Another Class1
– user248319