I want add a logger function to a worker class, how to pass a member function as a function pointer? use mem_fun?
here is the code sample:
class Work{
public:
void (*logger) (const string &s);
void do_sth(){if (logger) logger("on log")};
};
classs P{
public:
void log(const string &s)(cout << s);
};
int main(){
Work w;
P p;
w.logger = &p.log;
w.do_sth();
}
edit:
I don't want to use void (P::*xxx)() because it stick to class P...
I know C++ hide sth, the real log function is: void log(P &p, const string &s),
and the real project is like this:
I create a CDialog, and there is a log function, it copy the log string to a CEdit.
So I need pass this log function to a Worker class, this class do some serial port job,
I need log and show the data send and recived...