How to use member of a class in a local class in a method?
问题 I have a class like this: class A { protected: int t = 10; public: void f() { struct B { void g() { print(t); //using t } }; B b; b.g(); } }; ERROR: a nonstatic member reference must be relative to a specific object I see, members of class A is not visible in struct B (which is inside class A method). But how I may capture they, or make friends A and B? (If it's possible) 回答1: Defining B inside a method of A does not make instances of A contain a B . No matter where you define a class, you