I want to add a log function to a working class, how do I pass a member function as a function pointer? use mem_fun?
here is a sample code:
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 do not want to use void (P :: * xxx) () because it adheres to the class P ...
I know C ++ hide sth, the real log function: void log (P & p, const string & s),
and the real project is as follows:
I create a CDialog, and there is a log function, it copies the log line to CEdit.
So, I need to pass this log function to the Worker class, this class does some serial port job,
I need a log and show the data to send and receive ...
source share