There is a class in which two methods. One is public , the second is private . In a public method, I create a lambda and I want to call a private class method in it.

How can I do that?

    1 answer 1

    It is enough to transfer this to the lambda capture area:

     #include <iostream> struct S { void g() { std::cout << "public\n"; auto l = [this]() { std::cout << "lambda\n"; f(); }; l(); } private: void f() { std::cout << "private\n"; } }; int main() { S s; sg(); } 

    Test