c++调试出错,请高手帮个忙

来源:百度知道 编辑:UC知道 时间:2024/05/16 04:23:20
#include<iostream>
using namespace std;
template<class T>
class Cpoint
{
public:
Cpoint(T _x=0,T _y=0)
{
xx=_x;
yy=_y;
}
Cpoint operator +(Cpoint<T> c1)
{
return Cpoint(xx+c1.xx,yy+c1.yy);
}
Cpoint operator -(Cpoint<T> c2)
{
return Cpoint(xx-c2.xx,yy-c2.yy);
}
Cpoint operator ++()
{
return Cpoint(xx++,yy++);
}
Cpoint operator ++(int )
{
Cpoint c3;
return Cpoint(++c3.xx,++c3.yy);
}
void display()
{
cout<<"("<<xx<<","<<yy<<")"<<endl;
}
private:
T xx,yy;
};
void main()
{
Cpoint<int> c1(3,4),c2(2,3),c3;
c3=c1+c2;
c3.display();
c3=++c3;
c3.display();
c3=c3++;
c3.display();
Cpoint<double> c4(3.0,4.0),c5(2

软件问题。程序没有问题。

我在VC++6.0调试的没这些问题,程序没问题,可能是软件或者系统的问题

我给你改好了!你++运算符重载的不对
加(int)才是用后自增
#include<iostream>
using namespace std;
template<class T>
class Cpoint
{
public:
Cpoint(T _x=0,T _y=0)
{
xx=_x;
yy=_y;
}
Cpoint operator +(Cpoint<T> c1)
{
return Cpoint(xx+c1.xx,yy+c1.yy);
}
Cpoint operator -(Cpoint<T> c2)
{
return Cpoint(xx-c2.xx,yy-c2.yy);
}
Cpoint operator ++()
{
Cpoint temp(++xx,++yy);
return temp;
}
Cpoint operator ++(int)
{
return Cpoint(++xx,++yy);
}
void display()
{
cout<<"("<<xx<<","<<yy<<")"<<endl;
}
private:
T xx,yy;
};
void main()
{
Cpoint<int> c1(3,4),c2(2,3),c3;
c3=c1+c2;
c3.display();
c3=++c3;
c3.display();
c3=