purecpp-org / rest_rpc_old-out-of-date-now-

This is out of date, please move to https://github.com/qicosmos/rest_rpc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

使用 timax::to_function_pointer 编译报错

lq277012525 opened this issue · comments

auto f= timax::to_function_pointer([&](int a) {
a++;
return; });
直接编译报错
vs2017
error C2440: “static_cast”: 无法从“const main::<lambda_cb416210eb518a403ab0bff0bf3bd7ca>”转换为“void (__cdecl *)(int)”
是不是不能这样使用哦
我只是想试一下能不能把 lambda 转换到 函数指针 好去和一些 c 的api callback 搭配使用

你好,lambda表达式只有在没有catch任何变量的情况下,才能隐式转换为函数指针。

要是能 catch 变量就完美了 多谢解答 !!十分感谢

@lq277012525 标准作出了限定,做不到你希望的那样。你可以把它转成std::function再转成函数指针。