classcomplex{Private: DoubleReal_ =0.0; DoubleImag_ =0.0; Public: Complex ()=default; ExplicitComplex (DoubleRealDoubleimag): Real_ (Real), Imag_ (imag) {} Complex (Constcomplex&Other ) {Real_=Other.real_; Imag_=Other.imag_; } Complex (Complex&&Other ) {Real_=Std::move (Other.real_); Imag_=Std::move (other.imag_); } Complex&operator=(Constcomplex&Other ) {Real_=Other.real_; Imag_=Other.imag_; return* This; } Complex&operator= (complex&&Other ) {Real_=Std::move (Other.real_); Imag_=Std::move (other.imag_); return* This; } DoubleReal ()Const { returnReal_; } DoubleImag ()Const { returnImag_; } voidSetreal (Doublenewreal) {Real_=Newreal; } voidSetimag (DoubleNewimag) {Imag_=Newimag; }}; Complexoperator+(Constcomplex& C1,Constcomplex&C2) { returnComplex ((c1.real () + c2.real ()), (C1.imag () +C2.imag ()));} Complexoperator-(Constcomplex& C1,Constcomplex&C2) { returnComplex ((C1.real ()-c2.real ()), (C1.imag ()-C2.imag ()));} Complexoperator*(Constcomplex& C1,Constcomplex&C2) { Double ConstReal = C1.real () * C2.real ()-C1.imag () *C2.imag (); Double ConstImag = C1.real () * C2.IMAG () + c1.imag () *c2.real (); returnComplex (real, imag);} Complexoperator/(Constcomplex& C1,Constcomplex&C2) { Const DoubleDenominator = C2.real () * c2.real () + c2.imag () *C2.imag (); Complex Tmpcomplex (C2.real (),-C2.imag ()); Complex&& result = C1 *Tmpcomplex; Result.setreal (Result.real ()/denominator); Result.setimag (Result.imag ()/denominator); returnresult;}voidPrintConstcomplex&complex) {std::p rintf ("(%.1f,%.1f)", Complex.real (), Complex.imag ());}
Extremely simple plural class, just don't want to deduce again plural arithmetic