首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

lambda 如何设置调用约定呢

2013-09-28 
lambda 怎么设置调用约定呢std::for_each(begin,end,[&](const int a){std::coutastd::endl})这里的

lambda 怎么设置调用约定呢
std::for_each(begin,end,[&](const int a)
{
std::cout<<a<<std::endl;
});
这里的lambda怎么才能设置调用约定呢?
[解决办法]

引用:
Quote: 引用:

windows 回调只能接受函数指针吧,lambda 无法转换成函数指针的时候就没法做回调函数了。

lambda可以直接放进去的
比如
CreateThread(0,[](PVOID)->DWORD
{
std::cout<<"运行"<<std::endl;
},nullptr,nullptr,nullptr);
可以直接过编译,运行也没有问题。但是当一个函数的调用约定要_stdcall的时候就不行了

这种情况的 lambda 是可以转换成对应的函数指针的,所以能够作为回调函数。
c++11 5.1.2/6
The closure type for a lambda-expression with no lambda-capture has a public non-virtual non-explicit const conversion function to pointer to function having the same parameter and return types as the closure type’s function call operator. The value returned by this conversion function shall be the address of a function that, when invoked, has the same effect as invoking the closure type’s function call operator.
如果 [] 放了东西,这种隐式转换就不存在了,然后就无法作为回调函数了。
跟什么 call 没有关系。

热点排行