Are friend functions inherited? and why would a base class FRIEND function work on a derived class object?
问题 class baseClass { public: friend int friendFuncReturn(baseClass &obj) { return obj.baseInt; } baseClass(int x) : baseInt(x) {} private: int baseInt; }; class derivedClass : public baseClass { public: derivedClass(int x, int y) : baseClass(x), derivedInt(y) {} private: int derivedInt; }; in the function friend int friendFuncReturn(baseClass &obj) { return obj.baseInt; } I don't understand why would the friend function of the base class work for the derived class? should not passing derived