本文介绍了&是什么QUOT; [这里]"意味着C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我读 Cocos2dx 3.0
API,我发现这样的事情:
自动监听= [这](事件*事件){
汽车的KeyboardEvent =的static_cast< EventKeyboard *>(事件);
如果(keyboardEvent-> _is pressed)
{
如果(安其pressed!= nullptr)
安其pressed(keyboardEvent-> _key code,事件);
}
其他
{
如果(onKeyReleased!= nullptr)
onKeyReleased(keyboardEvent-> _key code,事件);
}
};
这是什么 [这]
是什么意思?在 C ++ 11
?
解决方案
It introduces a lambda - a callable function object. Putting this
in the brackets means that the lambda captures this
, so that members of this object are available within it. Lambdas can also capture local variables, by value or reference, as described in the linked page.
The lambda has an overload of operator()
, so that it can be called like a function:
Event * event = some_event();
listener(event);
which will run the code defined in the body of the lambda.
Yes.
这篇关于&是什么QUOT; [这里]"意味着C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!