一弦一柱 2017-05-29 13:34 采纳率: 100%
浏览 838
已采纳

c++新人,求大神。。。。(有关类与对象)

#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掉了吗?
解决方法又是什么?求大神。。。。

  • 写回答

1条回答 默认 最新

  • shifenglv 2017-05-29 14:32
    关注

    t是在一个方法中定义的,当然是局部变量了。方法执行完,变量t分得的内存会被释放掉。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突