使用stl中list的list.remove()函数删除结构体结点时,会遇到==的运算符重载问题,解决方法如下:
1 2 3 4 5 6
| struct msg { string studentNumber; string studentName; int gradeChinese, gradeMath, gradeEnglish; }
|
1 2 3 4 5 6 7 8 9 10
| bool operator ==(const CInfoFile::msg& msg1, const CInfoFile::msg& msg2) { bool flag = false; if (msg1.studentNumber == msg2.studentNumber &&msg1.studentName==msg2.studentName &&msg1.gradeChinese==msg2.gradeChinese &&msg1.gradeEnglish==msg2.gradeEnglish &&msg1.gradeMath==msg2.gradeMath) flag = true; return flag; }
|