//FooType and BarType not in the same hierarchy
bool operator==(const FooType &, const BarType &);
bool operator<(const FooType &, const BarType &);
例如,如果
FooType
是以自纪元以来的秒数为单位的double
类型,而BarType
是提供UTC日期的三个整数(年、月和日)的元组,则上述比较“有意义”。你见过这样的类型间比较吗?在C++社区中,它们是否被看作是不好的做法?
operator==(const FooType&)
应该是BarType
类的一个方法,而不是一个函数。 - chepnerif (time == {Day(13), Month(5), Year(1996)})
的操作。 - chris