Hacker News new | ask | show | jobs
by anthay 3251 days ago
It's probably a bit late for this reply, but... Another clumsy workaround is to use operator(). Again, standard C++ and this one has access to local variables:

    int g()
    {
        int x, y;

        struct local {
            int & a_;
            int & b_;
            local(int & a, int & b) : a_(a), b_(b) {}
        
            int operator()()
            {
                return a_ + b_;
            }

        } nested(x, y);

        x = 99; y = 1;
        return nested();
    }

    assert(g() == 100);