C++之类的比較运算符的重载
比較运算符的重载通常有两种方式:
第一:作为成员函数重载
曾经几章的Student类为例:
这里能够把(opetator==)理解为"成员函数名"。
bool Student::operator==(const Student &s) const { return this->name == s.name && this->age == s.age && this ->score == s.score; }第二:作为友元函数重载
bool operator== (const Student &s,const Student&s1){ return (s.age == s1.age && s.name == s1.name && s.score == s1.score); }