Friday 15 June 2012

class - Can I use method pointers in c++ alike delegates in c#? -


I want to create a square '(let's call it X for convenience) method using an indicator in its own right In cases where I am able to remove the code, which is different from the method only. For example, some blocks like:

  a (); B (); C(); MehtodCall (someResultOfabc); D (); E ();   

I would like to remove a method that will use different methods passed only as a pointer:

So I should do something similar:

  Zero X :: Extracted Method (Zero (x :: * Method Callpoints) (Type OffAbarsalt)) {a (); B (); C(); This- & gt; * MethodCallPointer (someResultOfabc); D (); E (); }   

and use such a function like this:

  zero: :: DoSomethingA () {ExtractedMethod (& X :: Edoir) ; } Zero X: DoSomethingB () (ExtractedMethod (& X :: BDoer);}   

and on OS ...

Unfortunately I'm stuck here, Because I get a compilation error, method pointer does not evaluate in the call that takes a debate.

I start to wander this, if X in this announcement is still an incomplete type?

I would be happy if someone would help me by telling me how to do this, or why not.

I really What does not want, is to actually get some work, such as signing and using the std :: function in Lambda, or using an indicator in a steady way which takes X * and invokes specific methods that I Neither do make the switch statement and a flag, nor use the interface instead of that switch statement, apply the strategy parter and as a parameter Use Ratejik instances;) They are not all the way to the solution of this case, but I do not want to read about other proceedings. The only thing that I like is "This is possible, and how to do it" in this way.

@Robert is correct, idiomatic way to use delegates in C ++ std :: function is to be used with std :: bind .

However, if you insist on using pointers-to-methods as an alternative solution for a proper representative, then the correct syntax is:

  zero X :: Extracted Method (Zero (X :: * Method Callpoints) (TypeofBRR)) {(This-> Method CardPorter) (Some Result Objects); // ^ ^ // Note the brackets, they are required    

No comments:

Post a Comment