更新时间2019-07-07 22:53:30
为complex类添加适当的构造类函数,并使用友元函数add实现复数加法
很基础的类定义(若是C++的)
class complex
{
public:
friend complex add(complex &x,complex &y);
complex()
{
real = 0.0;
imag = 0.0;
}
complex(float x, float y)
{
real = x;
imag = y;
}
private:
float real;
float imag;
};
complex add(complex &x,complex &y)
{
return complex( x.real+y.real,x.imag+y.imag);
}