# nested Lambda • ### Question

• Hi Igor, Mike and everybody
I am learning Lambda from the documentation.
I can do the following:
auto f=[](int x){return x+10;};
cout <<f(5)<<"\n";//Prints '15'
[=](int y){return x+y;};};

I have copied and pasted the following program from a website.
***************************************************
#include "stdafx.h"
#include <iostream>
#include <functional>

int main()
{
using namespace std;

// The following code declares a lambda expression that returns
// another lambda expression that adds two numbers.
// The returned lambda expression captures parameter x by value.
[line 10] auto addtwointegers = [](int x) -> function<int(int)> {
return [=](int y) { return x + y; };
};

// The following code declares a lambda expression that takes another
// lambda expression as its argument.
// The lambda expression applies the argument z to the function f
// and multiplies by 2.
auto higherorder = [](const function<int(int)>& f, int z) {
return f(z) * 2;
};

// Call the lambda expression that is bound to higherorder.

// Print the result, which is (7+8)*2.
}
+++++++++++++++++++++++++++++++++++++++++++++
I can't understand [line 20] where addtwointegers takes one parameter.
In [line 10], there are two paramters for it. Where has (7+8) come
from?

Thanks
Chong

Wednesday, July 30, 2014 3:10 AM

• 