一个C++重载运算符,总说有错误,哪位帮看看,谢谢
#include<iostream>usingnamespacestd;classComplex//复数类{private://私有doublereal;//实数doub...
#include<iostream>
using namespace std;
class Complex //复数类
{
private://私有
double real;//实数
double imag;//虚数
public:
void print()
{
cout<<real<<endl;
cout<<imag<<endl;
}
Complex(double real=0,double imag=0)
{
this->real=real;
this->imag=imag;
};
complex operator+(complex r);
};
complex complex::operator+(complex r)
{
return complex(this->real+r.real,this->imag+r.imag )
}
int main()
{
Complex com1(5,10),total,t(21,10);
total=com1+t;
total.print();
int a;
cin>>a;
return 0;
} 展开
using namespace std;
class Complex //复数类
{
private://私有
double real;//实数
double imag;//虚数
public:
void print()
{
cout<<real<<endl;
cout<<imag<<endl;
}
Complex(double real=0,double imag=0)
{
this->real=real;
this->imag=imag;
};
complex operator+(complex r);
};
complex complex::operator+(complex r)
{
return complex(this->real+r.real,this->imag+r.imag )
}
int main()
{
Complex com1(5,10),total,t(21,10);
total=com1+t;
total.print();
int a;
cin>>a;
return 0;
} 展开
2016-07-31
展开全部
#include<iostream>
using namespace std;
class Complex //复数类
{
private://私有
double real;//实数
double imag;//虚数
public:
void print()
{
cout<<real<<endl;
cout<<imag<<endl;
}
Complex(double real=0,double imag=0)
{
this->real=real;
this->imag=imag;
};
Complex operator+(Complex r);
};
Complex Complex::operator+(Complex r)
{
return Complex(this->real+r.real,this->imag+r.imag );
}
int main()
{
Complex com1(5,10),total,t(21,10);
total=com1+t;
total.print();
int a;
cin>>a;
return 0;
}
追问
问题出在哪呀,代码太多看的眼乱
追答
部分单词大小写有问题,少个分号
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询