c++ - How to invoke pointer to member function from static member function? -


I need to get a member function called by a standard function pointer, so I try to do abstract things like this Key:

Sample of class {Public: Virtual zero; some (zero) = 0; }; Class A: Public Sample {Nil to do something (zero); // details skipped}; Class B: Public Sampling {Nothing less (zero); // details skipped}; Class executives {public: Examiner (sample * sample): func (and sample-> doSomething) {} Fixed zero * executed (zero * data) {executable * px = data; (PX- & gt; * function) (); // invalid usage of error from static function (pX-> * pX- & gt; fancy); // Error indicator member type 'zero (sample: :) ​​()' // Incompatible private with 'object type' executives: zero (sample :: * func) (zero); }; Int main (zero) {one myA; B IB; Executor x0 (& amp; MYA); Examiner x1 (& amp; myB); External Invoc (& Examiner :: Execution, & x0); External Invoc (& Executioner :: Execution, & amp; x1); }

Externally invoke is a Linux system call, which takes the function pointer and data pointer. I want to use a static member function with this pointer as the data.

... and if I am a stable member of class like A or B then my idea class sample As an interface to create, which is enhanced by A and b .

My problem is that I do not know how the pointer is the Executioner :: Execute function from member character. The problem is that you need two objects inside execute -

An example of a execute which is func , and another example (received from a class) sample on which func will be applied. Therefore you do not have to do object inside execute , function:

  class executor {public: executor (sample * sample): obj (sample ) {} Fixed Zero * Execute (Zero * Data) {executable * px = static_cast & lt; Executor * & gt; (Data); PX- & gt; Obj- & gt; DoSomething (); } Private: Sample * obj; }; Int main () {// Note that `zero main ()` is not legal C ++ A myA; B IB; Executor x0 (& amp; MYA); Examiner x1 (& amp; myB); External Invoc (& Examiner :: Execution, & x0); External Invoc (& Executioner :: Execution, & amp; x1); }  

An indicator for the member function (like your original zero (sample :: * func) () ) identifies a function within a class But to call the store to the Object function, you still have to provide one.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -