class Person{
string name;
public:
T& operator*(){
return name;
}
bool operator==(const Person &rhs){
return this->name == rhs.name;
}
bool operator!=(const Person &rhs){
return !(*this == rhs); // Will *this be the string name or the Person?
}
}
如果*this
最终解引用this
到string
代替Person
,是否有保持的*
使用作为类之外的引用操作解决方法?
如果我不能放弃使用*this
而不能超载*
将是一个相当大的障碍。
超载适用于Person对象。但是'this'是一个人*指针*。 – Galik
@Galik这个评论应该是一个(接受的)答案。 – YSC