I am trying to pass a lambda to the CURLOPT_WRITEFUNCTION
.
The function expects a static function, however, I learned from this question that a lambda would be implicitly converted, and I could call the member function from the lambda.
auto callback = [](char * ptr_data, size_t size, size_t nmemb, string * writerData)
->size_t
{
if(writerData == NULL)
return 0;
size_t data_size = size * nmemb;
writerData->append(ptr_data, data_size);
return (int)data_size;
};
CURLcode code = curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, callback);
This actually compiles, but curl segfaults: Segmentation fault: 11
I pasted the full example here.