Why is it not possible to use private method in a lambda?

后端 未结 5 1365
醉酒成梦
醉酒成梦 2020-12-10 11:23

Having a class like this:

class A {
public:
    bool hasGrandChild() const;

private:
    bool hasChild() const;
    vector children_;
};

5条回答
  •  一个人的身影
    2020-12-10 11:55

    It isn't possible because the lambda is not a part of the class. It's the same as making an out-of-class function, and calling it instead of creating a lambda. Of course it doesn't have access to private members.

提交回复
热议问题