#include <iostream>

class Foo {
public:
    void f() {
        struct inner {
            void g(Foo& x) {
                x.h();
            }
        };
        inner obj;
        obj.g(*this);
    }
private:
    void h() {
        std::cout << "Works!" << std::endl;
    }
};

int main() {
    Foo foo;
    foo.f();
}