How to declare a function that accepts a lambda?

Posted by Andreas Bonini on Stack Overflow See other posts from Stack Overflow or by Andreas Bonini
Published on 2010-05-30T12:20:17Z Indexed on 2010/05/30 16:02 UTC
Read the original article Hit count: 221

Filed under:
|
|

I read on the internet many tutorials that explained how to use lambdas with the standard library (such as std::find), and they all were very interesting, but I couldn't find any that explained how I can use a lambda for my own functions.

For example:

int main()
{
    int test = 5;
    LambdaTest([&](int a) { test += a; });

    return EXIT_SUCCESS;
}

How should I declare LambdaTest? What's the type of its first argument? And then, how can I call the anonymous function passing to it - for example - "10" as its argument?

© Stack Overflow or respective owner

Related posts about c++

Related posts about lambda