Overloading Operators

Hi, I'm working on the following program and keep getting error message on the relational operator ==, <, << and >>. Error6 error C2511: 'bool TimeType::operator <(const TimeType &)' : overloaded member function not found in 'TimeType ', and on the other ones as well when I try to overload them.

1). Write the specification of a class named TimeType with the following members:
The relational operators <and ==
The stream insertion << to write data members of a TimeType object to an output stream.
The stream insertion >> to read data members of a TimeType object to an output stream.
2). Write the implementation of the == operator(return true if this time matches another time object passed as a parameter, return false otherwise).
Write the implementation of the << operator(writes the time in the format HOURS:MINUTES:SECONDS to an output stream).
Here is my code:

//Member Specifications.
class TimeType
{
public:
operator==(const &);<==ERROR
operator<(const &);<==ERROR
void operator <<(obj);<==ERROR
void operator >>(obj);<==ERROR
}

//Member Implementations.
bool TimeType :: operator==(const TimeType &time1)<==ERROR HERE
{
bool status;

if(time1==time1.time)
status=true;

return status;
}

ostream &operator << (ostream & strm, const TimeType &obj)<--ERROR HERE
{
strm<<obj.hour<<"HOURS"<<obj.minutes<<"MINUTES"<<obj.sec<<"SECONDS";
return strm;
}

any help appreciated
hey, you are missing things declaring the overloading operators. You have to put you class name before.
it should look like something like that:
1
2
3
4
5
6
7
8
class TimeType
{
public:
 TimeType& operator ==(const TimeType&);
 TimeType& operator <(const TimeType&);
 TimeType& operator <<(const TimeType&);
 TimeType& operator >>(const TimeType&);
};


that will give you a start.
I hope i helped you a bit.
Last edited on
@jonatashille, the >> and << operators should return istream& and ostream&, respectively. And, louflow, in your == operator you check if(time1==time1.time), which is full of errors. First of all you didn't implement the "time" element of you class, and second of all, you are checking if the object is equal to it's element, which is always false. You need if (time==time1.time)
got it thanks
Topic archived. No new replies allowed.