运行以下代码以使用朋友功能时出现错误。我的课XYZ1有一个朋友功能,它是ABC1类的成员函数(findMax)。我的类声明如下会员在C++中的功能为Friend功能
class XYZ1;
class ABC1
{
int a;
public :
ABC1()
{
a =20;
}
void findMax(XYZ1 p)
{
if (p.x > a) cout<< "Max is "<<p.x;
else cout <<"Max is "<<a;
}
};
class XYZ1
{
int x;
public :
XYZ1()
{
x =10;
}
friend void ABC1::findMax(XYZ1);
};
main()
{
XYZ1 p;
ABC1 q;
q.findMax(p);
}
错误:friend3.cpp:14:7:错误: 'P' 具有不完整的类型 friend3.cpp:4:7:错误: '结构XYZ1'
的向前声明请帮
“main”的返回类型在哪里? –