/*001*/ #ifndef __COMPLEX__
/*002*/ #define __COMPLEX__
/*037*/ #include <iostream.h>
/*004*/ class complex{
/*008*/ public:
/*009*/ complex (double r = 0, double i = 0)
/*010*/ : re(r), im(i) {}
/*011*/ double real () const { return re; }
/*012*/ double imag () const { return im; }
/*013*/ complex& operator += (const complex&);
/*006*/ private:
/*007*/ double re, im;
/*017*/ friend complex& __doapl(complex*, const complex&);
/*005*/ }
/*003*/ #endif
/*018*/ inline complex&
/*014*/ complex::operator += (const complex& r){
/*016*/ return __doapl(this, r);
/*015*/ }
/*024*/ inline complex&
/*019*/ __doapl(complex* ths, const complex& r){
/*021*/ ths->re += r.re;
/*022*/ ths->rm =+ r.im;
/*023*/ return *ths;
/*020*/ }
/*037*/ inline double
/*034*/ imag (const complex& x){
/*036*/ return x.imag ();
/*035*/ }
/*041*/ inline double
/*038*/ real (const complex& x){
/*040*/ return x.real ();
/*039*/ }
/*027*/ inline complex
/*025*/ operator + (const complex& x, const complex& y){
/*042*/ return complex (real(x) + real(y), imag(x) + imag(y));
/*026*/ }
/*030*/ inline complex
/*028*/ operator + (const complex& x, double y){
/*043*/ return complex (real(x) + y, imag(x));
/*029*/ }
/*033*/ inline complex
/*031*/ operator + (double x, const complex& y){
/*044*/ return complex (x + real(y), imag(y));
/*032*/ }
/*047*/ inline ostream&
/*045*/ operator << (ostream& os, const complex& x){
/*048*/ return os << '(' << real(x) << ',' << imag(x) << ')';
/*046*/ }
/*001*/ /*002*/ /*003*/ 防衛(wèi)聲明
/*004*/ /*005*/ class head
/*006*/ /*007*/ 數(shù)據放在private(without poniter)
/*008*/ /*009*/ /*010*/ 構造函數(shù) 無返回值 默認參數(shù) 初始化列表 拷貝構造/拷貝賦值編譯期自動生成且可用故不寫
/*011*/ /*012*/ 成員函數(shù)(常成員函數(shù)) 自動內聯(lián) pass by value/reference 都行
/*013*/-------- /*024*/ 操作符重載(成員函數(shù),帶this) 友元
/*025*/-------- /*044*/ 操作符重載(非成員函數(shù),無this) 臨時對象 return by value
`` `
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。