Use a friend function to overload the >> operator
class Time
{
private:
int hour, minute, second;
public:
Time() {hour = mijnute = second = 0;}
friend istream& operator >> (istream& in, Time& t);
};
// Put this in the *.cpp file, not the *.h file
istream& operator >> (istream& in, Time& t)
{
cout << "Enter time";
cin >> t.hour >> t.minute >> t.second;
return in;
};
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
At this stage(I am assuming), it may be easier( for you) to create a function, like so :
class Timer
{
int h,m,s;
public :
void getTime() { cin >> h >> m >> s; }
}
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608