title: Events vs boost::function
body: <p>Since code speaks better than words, would you use this:</p>
  
  <pre><code>struct StringEvent
  {
      const void* source;
      const std::string str;
  
      StringEvent(const void* source, const std::string&amp; str)
          : source(source), str(str) 
      { }
  };
  
  class StringEventListener
  {
  public:
      virtual void handler(const StringEvent&amp; event) = 0;
  }
  
  class Test : public StringEventListener
  {
  public:
      void handler(const StringEvent&amp; event) 
      { 
          std::cout &lt;&lt; event.str &lt;&lt; std::endl; 
      }
  }
  
  class EventSource
  {
  public:
      EventSource(StringEventListener* listener) 
      { 
          listener-&gt;handler(StringEvent(this, std::string("foo"))); 
      } 
  }
  
  int main()
  {
      Test test;
  
      EventSource(&amp;test);
  }
  </code></pre>
  
  <p>over this?</p>
  
  <pre><code>class Test 
  {
  public:
      void handler(const std::string&amp; str) 
      { 
          std::cout &lt;&lt; str &lt;&lt; std::endl; 
      }
  };
  
  class EventSource
  {
  public:
      EventSource(const boost::function&lt;void (const std::string&amp;)&gt;&amp; funcPtr)
      {
          funcPtr(std::string("foo"));
      }
  };
  
  int main()
  {
      Test test;
  
      EventSource(boost::bind(&amp;Test::handler, &amp;test, _1));
  }
  </code></pre>
  
  <p>to make the class EventSource call <code>test.handler("foo")</code>?</p>
  
  <p>Coming from the Java/C# world I find the first approach more intuitive, albeit verbose, but is it reccomanded to use in real-life situations, or does it cause more problems than it's worth/performance hits?</p>