Closures/Value capture: Difference between revisions

added c++
m (→‎{{header|Pike}}: whitespace)
(added c++)
Line 107:
0
</pre>
 
=={{header|C++}}==
{{works with|C++11}}
<lang cpp>#include <iostream>
#include <functional>
#include <vector>
 
int main() {
std::vector<std::function<int()> > funcs;
for (int i = 0; i < 10; i++)
funcs.push_back([=]() { return i * i; });
std::cout << funcs[3]() << std::endl;
 
return 0;
}</lang>
Output:
<lang>9</lang>
 
=={{header|C sharp|C#}}==
Anonymous user