Hello guys.
I was writing a simple program which I have to overload the << operator so as to display the class object using cout instead of to a use a method for that.
1 2 3 4 5 6
voidoperator<<(std::ostream &os, Time &t); // prototype within a header.h
//function definition in time.cpp
void Time::operator<<(std::ostream &s, Time &t)
{
s << t.hours << " hours " << t.minutes << " minutes << std::endl;
}
But the compiler keeps telling that error: 'void Time::operator<<(std::ostream&, const Time&)' must take exactly one argument|. I don't know what I was doing wrong. Please someone should point me out. Thanks
I have done all that you pointed out; making the return type reference to ostream object. defining the function as friend instread of class method, but I'm still having the same error message.
nvrmnd I didn't look closely to your comment and you didn't say it out. I shouldn't qualify the function with the Class qualifier and should be friend instead of class method. Thanks guys