O great god teach
CodePudding user response:
Urgent urgent!!!
CodePudding user response:
http://www.cnblogs.com/xianyunhe/archive/2011/11/26/2264709.html
CodePudding user response:
Because of the existence of this pointer parameter, a member function pointer, converted into a common function, is the need to make special treatment in the stack.
Look at the WTL's handling of the callback function.
Need to use a consortium to transform, and this pointer push into stack.
CodePudding user response:
http://www.cnblogs.com/memset/p/thunk_in_cpp.html
See this post
CodePudding user response:
Is not the whole a yourself
//conversion function Template Auto turn (R (f) T: : * (Args... )) { Return [f] (T, T * Args... The args) { (t - & gt; * f) (args... ); }; } //test Class A { Public: Int id; A (int x) : id (x) {} Void f () { cout } }; Int main () { A. a. (233); Auto f=turn (& amp; A: : f); F (& amp; a); return 0; } CodePudding user response:
reference 5 floor comiee reply: is not the whole one yourself //conversion function Template Auto turn (R (f) T: : * (Args... )) { Return [f] (T, T * Args... The args) { (t - & gt; * f) (args... ); }; } //test Class A { Public: Int id; A (int x) : id (x) {} Void f () { cout } }; Int main () { A. a. (233); Auto f=turn (& amp; A: : f); F (& amp; a); return 0; } Your code has a problem, there is no written like this CodePudding user response:
reference response: 7th floor thousand dream life , can't conversion, Look at this you understand https://www.cnblogs.com/findumars/p/8628053.html CodePudding user response:
refer to the eighth floor response: thousand dreams life Quote: reference response: 7th floor thousand dream life Unable to convert, Look at this you understand https://www.cnblogs.com/findumars/p/8628053.html A member function pointer width varies according to the compiler, In the VC compiler, can have 2 to 3 times the length of the pointer, unknown type member function pointer for 4 times, Under the compiler, if ordinary member function pointer, only this the sort of, there are all kinds of writing, Save the object A address, A * obj=0 x... ; Save function addresses the return value (A: : * func) (parameters)=0 x... ; Before I write the code, it doesn't allow me to mutual transformation between ordinary function pointer and a member function pointer, But know that the underlying are really just a function, an address, the data width is certain, the same So as the upstairs said, using the appropriate The union { The return value (A: : * func_T) (parameters); The return value (* func_S) (parameters); } Strong transfer can, -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- But are actually playing flower, The path Here said the right things -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1. Lambda, this can be, but I'm not familiar with, 2. STD: : bind (function address, object, the parameters of the function... )//return can return a pointer to a member function, this is only the function of a function, this function seems to be particularly good compatibility, can make a lot of things, For example: Int A: : func (int id) { return 0; } Function The callback (id); CodePudding user response:
You haven't said what you what to do. Member function object is needed to call, ordinary Pointers can call directly. So, from the function object + member function pointer to an ordinary pointer equivalent, What you need. If you have the object (like this), you can use the bind to get a simple function object, equivalent to an ordinary function pointer. Auto f=STD: : bind (& amp; MemFun, this); (f); CodePudding user response:
Reference: The class Test { Public: Void, _Callback, () { } }; The static void SCallBack (void * param) { If (param==NULL) { return; } The Test * Test=param (Test *); The test - & gt; , _Callback, (); } ////1 CALLABLE typedef void (*) (void * param); Void Func (CALLABLE CALLABLE, void * param) { CallAble (param); } ////2 The template & lt; The class T> Void Func1 (T callAble, void * param) { CallAble (param); } ////3 The template & lt; The class T, class C> CallAble void Func2 (T, C * TSH) { (TSH - & gt; * callAble) (); } ////4 The template & lt; The class T> Void Func4 callAble (T) { CallAble (); } Int main (int arg c, char * argv []) { //please pay attention to the life cycle, when necessary to use the smart pointer Test the Test; Func (SCallBack, & amp; Test). Func1 (SCallBack, & amp; Test). Func2 (& amp; The Test: :, _Callback,, & amp; Test). Func4 ([& amp; test] () { The test., _Callback, (); }); return 1; } Or: Search the Windows thunk