gku*_*min 5 c++ friend friend-class
目前我正在阅读一本书C++,它有一些练习。其中一个练习要求构建两个类,其中每个类都有一个用于另一个类的朋友方法。我目前的猜测是这样的:
#include <iostream>
using std::cout;
using std::endl;
class Y;
class X{
public:
void friend Y::f(X* x);
void g(Y* y){cout << "inside g(Y*)" << endl;}
};
class Y{
public:
void friend X::g(Y* y);
void f(X* x) {cout << "inside f(X*)" << endl;}
};
Run Code Online (Sandbox Code Playgroud)
但我的猜测无法编译,因为类X有void friend Y::f(X* x);方法声明。我怎样才能解决这个难题?请再给我一些猜测。
| 归档时间: |
|
| 查看次数: |
1361 次 |
| 最近记录: |