简单问题求指点错误。。。
编写一个程序实现复数的相加功能,并且可以把复数转化为双精度浮点数进行运算。。下面是我写的代码但是没法运行。。#include<iostream>
using namespace std;
class complex
{
public:
complex(){real=0;image=0;}
complex(double real,double image):real(r),image(i){}
complex(double r){real=r;image=0;}
operator double(){return real;}
friend complex operator +(complex &c1,complex &c2);
friend ostream & operator <<(ostream&,complex&);
void display();
private:
double real;
double image;
};
complex operator +(complex &c1,complex &c2)
{
return(c1.real+c2.real,c1.image+c2.image);
}
ostream& operator <<(ostream &output,complex &c)
{
output<<c.real<<"+"<<c.image<<"i"<<endl;
return output;
}
void complex::display()
{
cout<<c.real<<c.image<<endl;
}
int main()
{
complex c1(1,2),c2(2,3),c3;
double c4;
c3=c1+c2;
cout<<c3;
c4=c1+c2;
cout<<c4;
return 0;
}