C++11 adds a feature called lambda expression that can be used to add anonymous functions
Syntax: [Capture_block] (parameter) mutable exception_specification->return_type{body}
E.g An example of a click time
Auto btntest =-Addtoucheventlistener ([=] (REF * sender, Widget::toucheventtype type) { / /todo });
The return type void represented by the above example is omitted
[=] Captures all variables by value (all variables are obtained by means of the method);
[&] captures all variables by reference;
Here's a simple example.
function<intvoid> Testlambda (int x) { return [=] () int {return x * x;};} // because the return type and empty argument list of an expression in lambda can be omitted:function<intvoid> Testlambda (int x) { return [=]{return x * x;};}
Personal Summary: Lambda can be used to add a method that is called only once, as in JavaScript.
C++11 new feature lambda expression