vc++纠错

来源:百度知道 编辑:UC知道 时间:2024/06/06 00:21:42
#include <iostream>
using namespace std;
class CRect;
class CPoint
{
friend void CRect::Inflate(CPoint &a,int nOffset);
public:
CPoint(int a,int b)
{
xPos=a;
yPos=b;
}
void print()
{
cout<<"hello"<<xPos<<yPos<<endl;
}
private:
int xPos,yPos;
};
class CRect
{
void Inflate(CPoint &a,int nOffset);
};
CRect::Inflate(CPoint &a,int nOffset)
{
a.xPos=nOffset;
}

int main()
{
CPoint c(100,20);
CRect v;
v.Inflate(c,3);
c.print();
return 0;
}
一个简单的友员成员函数,错哪了/

#include <iostream>
using namespace std;
class CRect;
class CPoint
{
friend void CRect::Inflate(CPoint &a,int nOffset);
public:
CPoint(int a,int b)
{
xPos=a;
yPos=b;
}
是不是少了一个括号

编译器说“CRect”这个类没有被定义。
而且很明显class CRect;
这句是错的,起码要class CRect{};才行啊。
你应该把CRect类详细声明一下,包括它的成员函数、私有成员等……直接写class CRect;肯定不对!