struct point
{
int elem;
bool operator==(const point b) const
{
return this->elem == b.elem;
}
bool operator!=(const point b) const
{
return this->elem != b.elem;
}
bool operator<=(const point b) const
{
return this->elem <= b.elem;
}
bool operator<(const point b) const
{
return this->elem < b.elem;
}
bool operator>=(const point b) const
{
return this->elem >= b.elem;
}
bool operator>(const point b) const
{
return this->elem > b.elem;
}
}
重载运算符的格式如下:
bool operator 运算符 (const 结构体名称 b) const
{
return(什么时候这个运算符对结构体成立);//注意对此运算符使用this->元素名;
}
重点
bool operator<(const point s1) const
{
return this->v < s1.v;
}
所有的STL都会用到 < 小于号。
参考资料
https://blog.csdn.net/sunny1996/article/details/51242184