Is it possible to friend a class in an anonymous namespace in C++?
问题 I am porting code from Java to c++ and I'd like to replicate some anonymous functionalities. In file A.h I have : class A { private: int a; class AnonClass; friend class AnonClass; }; In file A.cpp I have : namespace { class AnonClass { public: AnonClass(A* parent) { parent->a = 0; // This doesn't work, a is not accessible } } } Is it possible to friend a class in an anonymous namespace in C++? In Java you can declare anonymous classes so it would be very similar. Also it would not expose