Lambda Expressions in C++

Sign in to queue

Description

In this interview, programming writer Thomas Petchel demonstrates how to use Lambda Expressions in C++.  You can also learn more in the topic: Lambda Expressions in C++.

Kathleen McGrath
Visual Studio User Education
http://blogs.msdn.com/kathleen

Embed

Download

Download this episode

The Discussion

  • User profile image
    joechung

    Functions can maintain state if you use static to declare the variables, e.g.,

     

    int next()
    {
        static int gn = 0;
        return gn++;
    }

     

    I don't recommend doing this, but it is technically possible, contrary to what was stated in the video.

     

    Also, the second program Thomas wrote summed the primes in the range [3..20], not the first 20 prime numbers.

  • User profile image
    zproxy

    Will extension methods also be there? Smiley

  • User profile image
    Thomas Petchel

    Hi Joe,

     

    Yes, you're correct that you can use static variables to maintain state between function calls. Perhaps it's better to say that lambda expressions enable you to share state between a function and its caller, because a static local variable is only accessible from the scope of the function in which it is defined.

     

    You also caught me saying "the first 20 prime numbers". I realized later that I said this. Thanks for the correction. Devil

     

     

  • User profile image
    jalf

    do we need them? Wink

    C++ allows non-member functions. Problem solved. Smiley

     

  • User profile image
    neilfmorrow​00

    I think lambda are great!!! I wish more people would learn how to use them when they first start learning how to program.  I sometimes find when you are teaching the basics of computer programming to beginning programmers the old-style methods are usually the best,

  • User profile image
    Corrector

    By the way, prime numbers start with 2, not 3!

  • User profile image
    wtf

    Where did the high quality video version go ?I can't see the text ! 

  • User profile image
    San

    I cant see the code in the video, can you please send me the code.

Add Your 2 Cents