#include <iostream>
using namespace std;
class Person{
public:
int id;
Person(int id){
this->id=id;
}
void toString(){
cout<<"{id:"<<this->id<<"}";
}
operator ==(const Person &p1,const Person &p2){
return p1.id==p2.id?true:false;
}
operator !=(const Person &p1,const Person &p2){
return p1.id==p2.id?false:true;
}
};
VC6.0中报错了:
error C2804: binary 'operator ==' has too many parameters
error C2333: '==' : error in function declaration; skipping function body
error C2804: binary 'operator !=' has too many parameters
error C2333: '!=' : error in function declaration; skipping function body
可是我试过了以下方法,还是不通过:
operator ==(const Person &p2){
return id==p2.id?true:false;
}
该怎么办呢? |