这里是我的代码示例: class X
{
public:
void f() {}
};
class Y : public X
{
public:
X& operator->() { return *this; }
void f() {}
};
int main()
{
Y t;
t.operator->().f();
我对朋友操作符重载感到困惑。如果我在头文件中编写friend运算符重载函数,它没有问题,但是一旦将函数移动到类文件,它会给我以下错误。我搜索了一些样本,他们都在头文件中写了函数。我做错了什么?谢谢。 ...: error: expected ‘,’ or ‘...’ before ‘&’ token
...: error: ISO C++ forbids declaration of ‘stat