title: How To Pass Handler with Variable Number of Arguments To A Class Using Boost Library If Needed
body: <p>This question has been haunting me for several days.  It looks very simple, but it's very difficult for me to figure it out.</p>
  
  <p>Basically, I want to do something like the async_wait function in the following code snippet</p>
  
  <pre><code>boost::asio::io_services    io;
  boost::asio::deadline_timer timer(io);
  timer.expires_from_now(boost::posix_time::milliseconds(1000));
  timer.async_wait(boost::bind(&amp;FunctionName, arg1, arg2, ...)); // How to implement this in my class A
  </code></pre>
  
  <p>My sample code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  //#include &lt;boost/*.hpp&gt; // You can use any boost library if needed
  
  // How to implement this class to take a handler with variable number of arguments?
  class A
  {
  public:
      A()
      {
  
      }
  
      void Do()
      {
          // How to call the handler with variable number of arguments?
      }
  };
  
  void FreeFunctionWithoutArgument()
  {
      std::cout &lt;&lt; "FreeFunctionWithoutArgument is called" &lt;&lt; std::endl;
  }
  
  void FreeFunctionWithOneArgument(int x)
  {
      std::cout &lt;&lt; "FreeFunctionWithOneArgument is called, x = " &lt;&lt; x &lt;&lt; std::endl;
  }
  
  void FreeFunctionWithTwoArguments(int x, std::string s)
  {
      std::cout &lt;&lt; "FreeFunctionWithTwoArguments is called, x = " &lt;&lt; x &lt;&lt; ", s =" &lt;&lt; s &lt;&lt; std::endl;
  }
  
  int main()
  {
      A a;
  
      a.Do(); // Will do different jobs depending on which FreeFunction is passed to the class A
  }
  </code></pre>
  
  <p>P.S.: you can use any boost library if needed, such as boost::bind, boost::function</p>