class X {
friend void clear() {
cout << "clear" << endl;
}
X() { }
void g();
};
void clear();
void X::g() { clear(); };
class X {
friend void clear() {
cout << "clear" << endl;
}
X() { }
void g();
};
void X::g() { clear(); };
void clear();
X类中的成员函数是Y类中的友元函数
class X {
public:
void clear();
};
class Y
{
public:
friend void X::clear();
private:
string s;
};
inline void X::clear()
{
Y y;
cout << y.s << endl;
};
引用版本也是一样
class Y;
class X {
public:
void clear(Y& y);
};
class Y
{
public:
friend void X::clear(Y& y);
private:
string s;
};
inline void X::clear(Y &y)
{
cout << y.s << endl;
};