I try to make a default lambda parameter for a class Mee which is a friend for class Foo . But I can not make the default lambda to have an access to the privates of Foo. Doesn't it should have the same access like the class Mee?
Here is class Foo that has private destructor, but class Mee is considered as friend and should have access.
class Foo
{
friend class Mee;
public:
Foo() {}
private:
virtual ~Foo() {};
};
Class Mee has an init function parameter which is set with default lambda. But the lambda can not access privates of Foo.
using InitFunc = std::function<void(Foo* p)>;
class Mee
{
public:
// |--- comiple error : Foo::~Foo': cannot access private member declared...
// |
// VVVVVVV
Mee(InitFunc fInitFunc = [](Foo* p) {delete p; })
{
delete m_p; // <-- thats ok, Mee has an access to Foo privates.
}
private:
Foo* m_p;
};