
Lambda Function
construct a closure: an unnamed function object capable of capturing variables in scope.
Syntax
[ capture-list ] ( params ) { body }
[ capture-list]:Capture list can be passed as follows (see below for the detailed description):
1.[a,&b] where a is captured by value and b is captured by reference.
2.[this] captures the this pointer by value
3.[&] captures all automatic variables odr-used in the body of the lambda by reference
4.[=] captures all automatic variables odr-used in the body of the lambda by value
5.[] captures nothing
Delegates and Lambda
What is delegate?
now let’s look at an example:
|
|
let’s say we want another class that keeps track of the longest message received so far:
|
|
with lambda functions we can easily bind var size_store into the function passed into setHandlerFunc
|
|




近期评论