楼上说的对,我再补充一下,friend还可以修饰类,友元类是能访问对方的protected函数和变量的。例如:class A{friend class B;protected: void protectedFun();....}class B{...}在class B中,可以直接访问class A的protected函数,比如 protectedFun函数