C++ lambda question!

  • Thread starter Thread starter Khanh01
  • Start date Start date
K

Khanh01

Guest
Hello, it seems that I am having significant confusion about lambda in .net and c ++,

Ex the lambda code in C ++


void print_modulo (const vector <int> & v, ostream & os, int m)

{
auto Modulo_print = [& os, m] (int x) {if (x% m == 0) os << x << '\ n'; };
for_each (begin (v), end (v), Modulo_print);
}


if I'm not mistaken, in .net when given os and m variables there is no need to add os and m to the beginning of the lambda expression. I'm having some confusion between these two languages.

//i mean, why not
auto Modulo_print = [] (int x) {if (x% m == 0) os << x << '\ n'; };

Can someone explain more help me! Thanks a lot.

Continue reading...
 
Back
Top