Having a class like this:
class A {
public:
bool hasGrandChild() const;
private:
bool hasChild() const;
vector children_;
};
You can capture this explicitly and make it a "member lambda" that has access to private members.
For example, consider the following sample:
#include
class A {
private:
void f() { std::cout << "Private"; }
public:
void g() {
[this] {
f();
// doesn't need qualification
}();
}
};
class B {
private:
void f() { std::cout << "Private"; }
public:
void g() { [] { f(); }(); } // compiler error
};
int main() {
A a;
a.g();
}