我自定义了一个类
class P {
public:
P(int a, int b, int c) :m_a(a), m_b(b), m_c(c) {}
bool operator == (const P&p)const {
if (p.m_a == this->m_a && p.m_b == this->m_b && p.m_c == this->m_c)
return true;
return false;
}
bool operator<(const P&p) const{
if (this->m_a != p.m_a) {
if (this->m_a < p.m_a)
return true;
else
return false;
}
if (this->m_b != p.m_b) {
if (this->m_b < p.m_b)
return true;
else
return false;
}
if (this->m_c != p.m_c) {
if (this->m_c < p.m_c)
return true;
else
return false;
}
A: return false;//**************************************
}
public:
int m_a;
int m_b;
int m_c;
};
声明了一个set<P>my_set;
我调用my_set.insert(P(1,2,3));3次,
当我在重载<那个函数里没加A语句时,发现3次都插入成功了,加了A语句发现
只插入了一次,想请问一下原因,我不是重载==了么,key值相同为什么还会重复插入呢?