search

Home  >  Q&A  >  body text

c++ lambda表达式的问题

一个函数指针名称申明
typedef void* (*SFThreadFuncPtr)(void* pUser);
[](void* _This) -> void*{}
为什么这个lambda没办法传给这个SFThreadFuncPtr定义的变量?

PHP中文网PHP中文网2803 days ago535

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 15:08:19

    [](void _This) -> void {}
    [](void _This) -> void{}
    编码~~

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 15:08:19

    The type of

    lambda expression is a closure and cannot be directly assigned to a pointer type. You can use std::function to wrap the lambda expression and then call it.

    #include <functional>
    
    std::function<void* (void*)> fun;
    
    fun = [](void* _This) -> void* { return NULL;};
    
    fun(NULL);

    reply
    0
  • Cancelreply