title: libusb callback_in function as a member of a class in C++
body: <p>I have a problem defining and using the callback function in <code>libusb_fill_bulk_transfer</code> when called as a member of a class in C++.</p>
  
  <p>Here is the definition in the class:</p>
  
  <pre><code>namespace usb_connector
  {
      class USBConnector
      {
      public:
          USBConnector();
          ~USBConnector();
          int connect(void);
          void read(void);
          void write(unsigned char *);
          void disconnect(void);
          void LIBUSB_CALL callback_in(struct libusb_transfer*);
  ...
  </code></pre>
  
  <p>Here is the implementation in the class:</p>
  
  <pre><code>void LIBUSB_CALL usb_connector::USBConnector::callback_in(struct libusb_transfer *transfer)
  {
      if (transfer == NULL) {
          cout &lt;&lt; "No libusb_transfer..." &lt;&lt; endl;
      }
      else {
          cout &lt;&lt; "libusb_transfer structure: " &lt;&lt; endl;
          cout &lt;&lt; "actual_length = " &lt;&lt; transfer-&gt;actual_length &lt;&lt; endl;
          for (int i = 0; i &lt; transfer-&gt;actual_length; i++) {
              cout &lt;&lt; transfer-&gt;buffer[i];
          }
          cout &lt;&lt; endl;
      }
  
      return;
  }
  </code></pre>
  
  <p>And here is how I call it:</p>
  
  <pre><code>...
  ...
  libusb_fill_bulk_transfer( transfer_in, usb_dev, USB_ENDPOINT_IN,
              in_buffer,  LEN_IN_BUFFER, callback_in, NULL, 0);
  ...
  ...
  </code></pre>
  
  <p>The error I get is the following:</p>
  
  <blockquote>
    <p>error: cannot convert 'usb_connector::USBConnector::callback_in' from type 'void (usb_connector::USBConnector::)(libusb_transfer*)' to type 'libusb_transfer_cb_fn {aka void (<em>)(libusb_transfer</em>)}'
                     in_buffer,  LEN_IN_BUFFER, callback_in, NULL, 0);</p>
  </blockquote>
  
  <p>How can I have the callback function as a member of a class and how do I make a call to it?</p>