CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #5
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Lightbulb Re: Declare Member Function that accept Functor

    I'm not sure that you want a functor here. I have usually seen multiple inheritance as a way of solving this. Create an interface class called EventHandler which provides a pure virtual function called processEvent. All observers must inherit from this interface and register with an event supplier. Of course it is possible that it is the only base class needed for some. The point is that an observer could implement any number of interfaces with multiple inheritance. In your case the Observer class could be the event handler and the call back function name can be whatever you wish. You can use dynamic_cast to ensure that the event handler objects implement the observer interface. I'm not sure what your myForeach is supposed to be. If you have a container of pointers you can use std::for_each and create a functor that calls processEvent on each object since you have a container of observers that provides iterator support.
    Last edited by kempofighter; June 1st, 2010 at 06:27 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured