title: How to write a C++ wrapper class method of a C function that takes callback?
body: <p>Given the following C interface:</p>
  
  <pre><code>IoT_Error_t aws_iot_mqtt_subscribe(AWS_IoT_Client *pClient,
                                     const char *pTopicName,
                                     uint16_t topicNameLen,
                                     QoS qos,
                                     pApplicationHandler_t pApplicationHandler, 
                                     oid *pApplicationHandlerData);
  </code></pre>
  
  <p>"<code>aws_iot_mqtt_subscribe</code> stores its arguments for latter reference - to call, in response to some event at some later point in time"</p>
  
  <p>Handler:</p>
  
  <pre><code>typedef void (*pApplicationHandler_t)(
      AWS_IoT_Client *pClient,
      char *pTopicName,
      uint16_t topicNameLen,
      IoT_Publish_Message_Params *pParams,
      void *pClientData);
  </code></pre>
  
  <p>I am trying to wrap this into a C++ class that would have the following interface:</p>
  
  <pre><code>class AWS {
  // ...
  public:
    void subscribe(const std::string &amp;topic,
                   std::function&lt;void(const std::string&amp;)&gt; callback);
  // ...
  };
  </code></pre>
  
  <p>My goal is to make it possible to pass a capturing lambda function to <code>AWS::subscribe</code>. I have been trying with different approaches for a nearly a week now but none of them seemed to work.</p>
  
  <p>Let me know if anything else needed to understand the problem, I'm happy to update the question.</p>