mercredi 24 janvier 2018

How to access private member from lambda that is passed to constructor of friendly class?

How can I access static member from lambda here?

    class A
    {
    public:
        A(std::function<void()> f)
        {
            f();
        }
    };

    class B
    {
    private:
        friend class A;
        static bool c;
    };

    bool B::c = false;

    A a([]() { B::c = true; });

This code gives me error C2248: 'B::c': cannot access private member declared in class 'B'

Aucun commentaire:

Enregistrer un commentaire