#include
#include
using namespace std;
//声明类
class Date{
public:
Date(double h,double m)
{real=h;
imag=m;
}
Date(){real=0;
imag=0;
}
Date(double &r)
{
real=r;imag=0;
}
friend Date operator +(Date &c1,Date &c2);
void display();
private:
double real;
double imag;
};
Date operator +(Date &c1,Date &c2)
{
return Date(c1.real+c2.real,c1.imag+c2.imag);
}
void Date::display()
{
cout<}
int main(){
//Date c1(3,4),c2(5,-10),c3;你的定义,不可以这样定义的,一个一个定义吧,当然连续定义也是可以的
//只是不可以像你这那,可以这样做
// Date c1_,c2_,c3_;
// c1_=Date(3,4);
//c2_=Date(5,-10);
Date c1(3,4);
Date c2(5,-10);
Date c3;
c3=c1+c2;
c3.display();
system("pause");
return 0;
}
--------------------next---------------------
阅读(1248) | 评论(0) | 转发(0) |