diff --git a/OOP/13Exam/3.4.cpp b/OOP/13Exam/3.4.cpp index 603addd..db681ce 100644 --- a/OOP/13Exam/3.4.cpp +++ b/OOP/13Exam/3.4.cpp @@ -9,7 +9,7 @@ public: cout << "Constructor!"; display(); } - complex(complex &c) : r(c.r), i(c.i) { + complex(const complex &c) : r(c.r), i(c.i) { cout << "Copy Constructor!"; display(); }; @@ -23,14 +23,11 @@ private: }; complex complex::operator+(complex c2) { - complex result(r + c2.r, i + c2.i); - return result; + return complex(r + c2.r, i + c2.i); } complex complex::operator-(complex c2) { - complex result(r - c2.r, i - c2.i); - return result; - // return complex(r - c2.r, i - c2.i); + return complex(r - c2.r, i - c2.i); } void complex::display() { diff --git a/OOP/15Exam/3.6.cpp b/OOP/15Exam/3.6.cpp index 5c82a21..c2febf9 100644 --- a/OOP/15Exam/3.6.cpp +++ b/OOP/15Exam/3.6.cpp @@ -12,7 +12,7 @@ public: // 外部接口 cout << "Constructor!"; display(); } - complex(complex &c) : r(c.r), i(c.i) { + complex(const complex &c) : r(c.r), i(c.i) { // this->num = ++count; // cout << "(Num: " << this->num << ")"; @@ -37,9 +37,10 @@ private: }; complex complex::operator+(complex c2) { - complex result(r + c2.r, i + c2.i); - return result; + // complex result(r + c2.r, i + c2.i); + // return result; + return complex(r + c2.r, i + c2.i); // 原文:return complex(r + c2.r, i + c2.i),不能编译=_= }