title: Vector of functions with parameters
body: <p>I have made vectors that contain functions, but they had no argument list. Also, they were not inside of a class. I have a class named <code>Dialog</code>, and I need to store function-pointers with a specific signature. Here is my typedef for these functions:</p>
  
  <pre><code>typedef INT_PTR (*MsgHandler)(WPARAM,LPARAM);
  </code></pre>
  
  <p>But, since the vector that contains these <code>MsgHandler</code>'s will be in my <code>Dialog</code> class, which will be inherited by my <code>CMainWnd</code> class, when I try to push_back the function, the signature of the function is different than that of <code>MsgHandler</code>. Here is my code, the 4 variations of trying to push_back the function in the vector, and the resulting errors for each of them:</p>
  
  <pre><code>typedef INT_PTR (*MsgHandler)(WPARAM,LPARAM);
  
  class Dialog
  {
  protected:
      Dialog(void); // Must be inherited
      vector&lt;MsgHandler&gt; Handlers;
  }
  
  class CMainWnd : public Dialog
  {
  public:
      INT_PTR MyHandler(WPARAM wp, LPARAM lp) {
          return TRUE;
      }
  
      CMainWnd(void) {
          // Attempt 1: Handlers.push_back(MyHandler);
          // Attempt 2: Handlers.push_back(&amp;MyHandler);
          // Attempt 3: Handlers.push_back(CMainWnd::MyHandler);
          // Attempt 4: Handlers.push_back(&amp;CMainWnd::MyHandler);
      }
  };
  </code></pre>
  
  <p>Attempt 1 yields the following error:</p>
  
  <pre><code>error C3867: 'CMainWnd::MyHandler': function call missing argument list; use '&amp;CMainWnd::MyHandler' to create a pointer to member
  </code></pre>
  
  <p>Attempt 2 yields:</p>
  
  <pre><code>error C2276: '&amp;' : illegal operation on bound member function expression
  </code></pre>
  
  <p>Attempt 3 yields:</p>
  
  <pre><code>error C3867: 'CMainWnd::MyHandler': function call missing argument list; use '&amp;CMainWnd::MyHandler' to create a pointer to member
  </code></pre>
  
  <p>Attempt 4 yields:</p>
  
  <pre><code>error C2664: 'std::vector&lt;_Ty&gt;::push_back' : cannot convert parameter 1 from 'INT_PTR (__thiscall CMainWnd::* )(WPARAM,LPARAM)' to 'const MsgHandler &amp;'
  </code></pre>
  
  <p>I think attempt 4 is the closest to being correct, but as stated previously since the function is a member, it alters the signature.
  How can I store function-pointers in the vector that is defined in the inherited class <code>Dialog</code> that:</p>
  
  <ul>
  <li>Have a return type of <code>INT_PTR</code></li>
  <li>Have two parameters, the first being a <code>WPARAM</code>, and the second being a <code>LPARAM</code></li>
  <li>Are a member of the derived class whose constuctor is the one adding them to the vector</li>
  </ul>
  
  <p>I have heard of using <code>boost::function</code> for doing things like this, but I have looked up documentation for it and I have no idea how to use it, it all seems confusing to me. I would very much like to just add the functions to the vector as if they were variables instead of bogging down my code with bind operations and what not. (May just be because I am ignorant when it comes to boost functions).</p>
  
  <p>What am I doing wrong here, or can I use <code>boost::function</code> to do this? For the <code>boost::function</code> way, I have tried declaring the vector as <code>vector&lt;boost::function&lt;INT_PTR(WPARAM,LPARAM)&gt;&gt;</code> and tried adding <code>MyHandler</code> to it, but that did not work. I would prefer not to use boost if I don't have to, but if someone suggests the boost way of doing this, please clarify how I could do this?</p>