Passing capturing lambda as function pointer

前端 未结 9 2399
-上瘾入骨i
-上瘾入骨i 2020-11-21 06:58

Is it possible to pass a lambda function as a function pointer? If so, I must be doing something incorrectly because I am getting a compile error.

Consider the follo

9条回答
  •  半阙折子戏
    2020-11-21 07:30

    A shortcut for using a lambda with as a C function pointer is this:

    "auto fun = +[](){}"
    

    Using Curl as exmample (curl debug info)

    auto callback = +[](CURL* handle, curl_infotype type, char* data, size_t size, void*){ //add code here :-) };
    curl_easy_setopt(curlHande, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curlHande,CURLOPT_DEBUGFUNCTION,callback);
    

提交回复
热议问题