c++ - Passing a Functor as a param to a method -


I have the following two classes that display the command pattern (unfortunately, both have a unique method name.)

  // pseudocode class member {virtual zero (cost event & amp;) = 0; } Class Dissertation {virtual zero dispatch (Const event & amp;) = 0; }   

I have a class template that has some sort of list with a method to iterate on this list.

  // pseudocode template & lt; Typename T & gt; Class registry {typedef list & lt; T & gt; ObjectList; Objectitist_baze; Zero iteration (const event and event) {for_each (_objects.begin (), _objects.end (), ...); // is not sure what to do here}}   

I would like to use mem_fun to create a function that calls As appropriate, I am able to make a simple use case, where I invoke a method without any parameter Ie

  // pseudocode class is simple {zero simple} {/*...*/}}   

and then I repeat:

  Fo R_each (_objects.begin (), _objects.with (), mem_fun (& simple :: simple);   

Unfortunately, I do not know how it looks when looking at the hemorrhoids That is, I can pass on to an absolute, but I do not understand in C ++ what I have to do.

Finally, I want to repeat The method accepts a type of draft, so it will set fire to that method on every method in the list.

I would like to avoid Boost ... It seems that this framework is completely possible without dragging it into the mix.

Thank you!

This can be the most straightforward way:

  Making the event event_forwarder // private in the public {public: event_forwarder (event and Event): mEvent (event) {} Zero operator (Subscriber and Sub-center Rebear) Const {Customer. Receave (Mentor); } Zero operator () (Dispatcher and Dispatcher) const {dispatcher.dispatch (mEvent); Private: Const event & amp; MEvent; };   

then:

  for_each (_objects.begin (), _objects.end (), event_forwarder (event));    

Comments