Где я накосячил?! Ни как понять не могу.
#include <iostream>
using namespace std;
class TTime {
public:
unsigned int h;
unsigned int m;
unsigned int s;
TTime(int h = 0, int m = 0, int s = 0) {
this->h = h;
this->m = m;
this->s = s;
}
TTime(TTime & t) {
this->h = t.h;
this->m = t.m;
this->s = t.s;
}
TTime & operator = (TTime const & a) {
this->h = a.h;
this->m = a.m;
this->s = a.s;
return *this;
}
bool operator==(TTime& a) const {
return ((a.h == this->h) && (a.m == this->m) && (a.s == this->s));
}
bool operator!=(TTime& a) const {
return !(*this == a);
}
bool operator> (const TTime& a) const {
return ((this->h > a.h) && (this->m > a.m) && (this->s > a.s));
}
bool operator< (const TTime& a) const {
return ((this->h < a.h) && (this->m < a.m) && (this->s < a.s));
}
bool operator>= (const TTime& a) const {
return ((this->h >= a.h) && (this->m >= a.m) && (this->s >= a.s));
}
bool operator<= (const TTime& a) const {
return ((this->h <= a.h) && (this->m <= a.m) && (this->s <= a.s));
}
};
int main(void)
{
TTime *t1 = TTime(1,2,3);
TTime *t2 = TTime(4,5,6);
TTime *t3 = TTime(1,2,3);
TTime *t4 = TTime(7,8,9);
if(t1 == t3) {
// Не отрабатывает!
}
t4 = t2;
if(t2 == t4) {
...
// Отрабатывает!
}
}
Пользователь добавил сообщение 23 Апреля 2016, 03:00:23:
Я пробовал даже вот такие сомнительные конструкции, вроде этой:
friend bool operator==(const TTime& left, const TTime& right) {
return ((left.h == right.h) && (left.m == right.m) && (left.s == right.s));
}
Всё равно не получается.