#include using namespace std; //主題:overloading重載運算子 //用途:若想將兩個『物件變數』進行 +、-、*、/ 運算 //方法:在 C++ 中,可以透過『重載運算子』來達到目的 //指令:傳回型態 類別名稱::operator#(參數列) { // // 實作重載內容 //} //傳回型態 operator++(); // 前置,例如 ++x //傳回型態 operator++(int); // 後置,例如 x++ //傳回型態 operator--(); // 前置,例如 --x //傳回型態 operator--(int); // 後置,例如 x-- //本題目的:建立複數物件,建立『+』運算子,讓兩個複數相加 //class class Complex { private: double real; double imaginary; public: Complex(double r,double i) { this->real = r; this->imaginary = i; } Complex() { this->real = 0; this->imaginary = 0; } void show(); Complex operator+(Complex c2) { Complex c1,c3; c1.real = this->real; c1.imaginary = this->imaginary; c3.real = c1.real + c2.real; c3.imaginary = c1.imaginary + c2.imaginary; return c3; } }; void Complex::show() { cout<<"(r,i) = ("<