title: Using a void function as a callback, convert from "std::function<void ()>?
body: <p>I have a boost::Asio based serial port reader that uses a callback, as follows:</p>
  
  <pre><code>void received(const char *data, unsigned int len)
  {
  
          string s(data, len);
          cout &lt;&lt;  s  &lt;&lt; endl;    
  
  }
  
  int main()
  {
  
      try {
          CallbackAsyncSerial serial("COM4", 115200);
          serial.setCallback(received);
          for(;;)
          {
              if(serial.errorStatus() || serial.isOpen()==false)
              {
                  cerr&lt;&lt;"Error: serial port unexpectedly closed"&lt;&lt;endl;
                  break;
              }
              char c;
              cin.get(c); //blocking wait for standard input
             serial.write(&amp;c,1);
          }
          quit:
          serial.close();
      } catch (std::exception&amp; e) {
          cerr&lt;&lt;"Exception: "&lt;&lt;e.what()&lt;&lt;endl;
      }
  
  }
  </code></pre>
  
  <p>This, as above, compiles and runs. Now I need to merge it into an existing class, so i have:</p>
  
  <pre><code>void MyClass::received(const char *data, unsigned int len)
  {
  
          string s(data, len);
          cout &lt;&lt;  s  &lt;&lt; endl;    
  
  }
  
  int MyClass::main()
  {
  
      try {
          CallbackAsyncSerial serial("COM4", 115200);
          serial.setCallback(received); //COMPILE ERROR HERE
          for(;;)
          {
              if(serial.errorStatus() || serial.isOpen()==false)
              {
                  cerr&lt;&lt;"Error: serial port unexpectedly closed"&lt;&lt;endl;
                  break;
              }
              char c;
              cin.get(c); //blocking wait for standard input
             serial.write(&amp;c,1);
          }
          quit:
          serial.close();
      } catch (std::exception&amp; e) {
          cerr&lt;&lt;"Exception: "&lt;&lt;e.what()&lt;&lt;endl;
      }
  
  }
  </code></pre>
  
  <p>However, adding <code>MyClass::received</code> stops the compile, giving me:</p>
  
  <pre><code>Error (active)  E0415   no suitable constructor exists to convert from "void (const char *data, unsigned int len)" to "std::function&lt;void (const char *, size_t)&gt;"
  </code></pre>
  
  <p>I have tried adjusting it to:</p>
  
  <p><code>std::function&lt; void() &gt;received(const char *data, unsigned int len);</code></p>
  
  <p>But i see the same thing. 
  What do i need to do here?</p>