Tag: friend
-
Why does the derived class have access to the private field of the base class?
10 class Base { public: class FirstBase { friend class Base; int x = 10; }; class SecondBase : public FirstBase { public: SecondBase() : FirstBase() {} void t() { std::cout << FirstBase::x; } }; }; This code compiles and works, but I don’t understand why it works. Can explain or cite sources to read?…