Call method inside lambda expression

c++, c++11, lambda

Solution

You need to capture `this`, either explicitly or implicitly:

std::for_each(l.begin(), l.end(),
    [this](my_obj& o){ // or [=] or [&]
      my_method(o); // can be called as if the lambda was a member
    });

Problem

I want to call a method of my class inside a lambda expression: ``` void my_class::my_method(my_obj& obj) { } void my_class::test_lambda() { std::list<my_obj> my_list; std::for_each(my_list.begin(), my_list.end(), [](my_obj& obj) { // Here I want to call my_method: // my_method(obj); }); } ``` How can I do?

Original source