求高手指出下面两个类之间的相互调用的错误,小弟刚开始学

C++语言 码拜 9年前 (2015-11-15) 1307次浏览
#include <iostream>
using namespace std;
class CPoint
{
public:
unsigned x;
unsigned y;
bool IsInCircle(CCircle *circle)
{
return (((x – circle->Center.x) * (x – circle->Center.x)
+ (y – circle->Center.y) * (y – circle->Center.y))
<= circle->Radius * circle->Radius);
}
};
class CCircle
{
public:
unsigned Radius;
CPoint Center;
};
int main()
{
return 0;
}
解决方案:40分
改一下顺序,原因是在CPoint编译时还不知道CCircle是什么东西

#include <iostream>
using namespace std;
class CCircle;
class CPoint
{
public:
	unsigned x;
	unsigned y;
	bool IsInCircle(CCircle *circle);
};
class CCircle
{
public:
	unsigned Radius;
	CPoint Center;
};
bool CPoint::IsInCircle(CCircle *circle)
{
	return (((x - circle->Center.x) * (x - circle->Center.x)
		+ (y - circle->Center.y) * (y - circle->Center.y))
		<= circle->Radius * circle->Radius);
}
int main()
{
	return 0;
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求高手指出下面两个类之间的相互调用的错误,小弟刚开始学
喜欢 (0)
[1034331897@qq.com]
分享 (0)