#include "stdafx.h"
#include
#include
using namespace std;
class point
{
float x, y;
public:
point() :x(0), y(0){}
~point(){}
point& operator++();
point& operator++(int);
float Area(point , point );
friend class rect;
};
point& point::operator++()
{
x++, y++;
return *this;
}
point& point::operator++(int)
{
point t=*this;
++x;
++y;
return t; //警告
}
float point::Area(point pointa, point pointb)
{
float SX = (pointa.x - pointb.x)*(pointa.x - pointb.x);
float SY = (pointa.y - pointb.y)*(pointa.y - pointb.y);
float s = sqrt(SX + SY);
return s;
}
class rect
{
point pointa, pointb;
public:
rect(){};
~rect(){};
bool operator>(rect);
bool operator<(rect);
};
bool rect::operator>(rect B)
{
if (Area(pointa, pointb) > Area(B.pointa, B.pointb)) //错误
return 1; else return 0;
}
bool rect::operator<(rect B)
{
if (Area(pointa, pointb) < Area(B.pointa, B.pointb)) //错误
return 1; else return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
rect A, B;
cout << (A>B);
system("pause");
return 0;
}
...........................
错误
error C3861: “Area”: 找不到标识符
IntelliSense: 未定义标识符 "Area"
警告
warning C4172: 返回局部变量或临时变量的地址
为什么会给出一个警告,是因为t在后置++重载执行完之后被delete掉了吗?
解决方法又是什么?求大神。。。。