First, note that the boolean type is just bool
.
Second, the return type of the time_Equal
declaration is int
, whereas the definition has Boolean
. Pretty sure you want both to be bool
. They should at least match.
Third, your time_Equal
function does not modify its arguments, so you should make them const
references (const Time &a
and const Time &b
).
Fourth, your time_Equal
function is a non-static member of Time
, but it doesn't use any of its members. That is, its output depends only on its arguments, and not on the object that this
points at. This is a code smell. It means your function should probably be a static function or you should change the function to use this
. So you have two options:
Keep it a member and change it to:
bool time_Equal(const Time &other) const;
And then in the implementation you should compare
*this
with theother
argument. In this case, you would call it likea.start.time_Equal(b.start)
.Make it either a
static
member or take it out of the class and make it a friend function and keep it with two arguments:bool time_Equal(const Time &a, const Time &b) const;
In this case, you would call it like
time_Equal(a.start, b.start)
.
Fifth, C++ has a built in operator to perform test for equality (==
) which you can overload for a class. So you can in fact implement the above two options respectively like so:
bool operator==(const Time &other) const; // As a non-static member
// or
bool operator==(const Time &a, const Time &b) const; // As a static member or friend function
Then you can compare times like so: a.start == b.start
. Nice, huh?
For more information, see the operator overloading FAQ.
Sixth, your time_Equal
implementation does not return false
when it should. You can easily rewrite the body as:
return a.hour == b.hour && a.minute == b.minute;