anthony
2007.07.17, 04:44 PM
Hi,
I'm trying to use a set to store classes (Messages) because it will sort them (based on the time they should be sent) and also prevent any duplicates.
However, I'm having trouble to get the 'operator<'
I've written it as a member function of my Message class because I figured set would look there to call it, but I get the following error:
error: no match for 'operator<' in '__x < __y'
note: candidates are: bool Message::operator<(Message&)
I've tried to write the function as close to the described way:
template <class _Tp>
struct less : public binary_function<_Tp, _Tp, bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x < __y; }
};
But when I do that I'm told my function (operator<(const Message &m1, const Message &m2) ) must only take ONE argument.
This is my attempt at overloading:
inline bool Message::operator<(Message &m2)
{
if (*this == m2)
{
return false;
}
else
{
return (GetDispatchTime() < m2.GetDispatchTime());
}
}
Any ideas?
Thanks
Anthony
I'm trying to use a set to store classes (Messages) because it will sort them (based on the time they should be sent) and also prevent any duplicates.
However, I'm having trouble to get the 'operator<'
I've written it as a member function of my Message class because I figured set would look there to call it, but I get the following error:
error: no match for 'operator<' in '__x < __y'
note: candidates are: bool Message::operator<(Message&)
I've tried to write the function as close to the described way:
template <class _Tp>
struct less : public binary_function<_Tp, _Tp, bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x < __y; }
};
But when I do that I'm told my function (operator<(const Message &m1, const Message &m2) ) must only take ONE argument.
This is my attempt at overloading:
inline bool Message::operator<(Message &m2)
{
if (*this == m2)
{
return false;
}
else
{
return (GetDispatchTime() < m2.GetDispatchTime());
}
}
Any ideas?
Thanks
Anthony