class Complex{ public: Complex(char* name,int id,int age){ this->pName = new char[strlen(name) + 1]; strcpy(this->pName, name); this->mID = id; this->mAge = age; } //重载==号操作符 bool operator==(const Complex& complex){ if (strcmp(this->pName,complex.pName) == 0 && this->mID == complex.mID && this->mAge == complex.mAge){ return true; } return false; } //重载!=操作符 bool operator!=(const Complex& complex){ if (strcmp(this->pName, complex.pName) != 0 || this->mID != complex.mID || this->mAge != complex.mAge){ return true; } return false; } ~Complex(){ if (this->pName != NULL){ delete[] this->pName; } } private: char* pName; int mID; int mAge; }; void test(){ Complex complex1("aaa", 10, 20); Complex complex2("bbb", 10, 20); if (complex1 == complex2){ cout << "相等!" << endl; } if (complex1 != complex2){ cout << "不相等!" << endl; } }