I cant seem to figure out where Im making a mistake here, to me it seems it should work, but Im getting an error: 'bool operator>(const Time&)' must take exactly two arguments.
I dont quite understand this.
#ifndef TIME_H
#define TIME_H
class Time
{
public:
Time();
Time (int h, int m, int s);
void displayTime();
booloperator>(const Time& other);
private:
int hours;
int minutes;
int seconds;
};
#endif // TIME_H
#include <iostream>
#include "Time.h"
usingnamespace std;
Time::Time(){
hours = 0;
minutes = 0;
seconds = 0;
}
Time::Time(int h, int m, int s){
hours = h;
minutes = m;
seconds = s;
}
void Time::displayTime(){
cout << "Hours: " << hours <<" Minutes: " << minutes << " Seconds: " <<seconds <<endl;
}
booloperator>(const Time &other){ //THIS IS WHERE THE ERROR IS SHOWING
if (hours > other.hours){
returntrue;
}
if (hours == other.hours && minutes > other.minutes){
returntrue;
}
if (minutes == other.minutes && seconds > other.seconds){
returntrue;
}
returnfalse;
}
Can someone point out my mistake?
Or am I doing this completely wrong?
The premise is that the user enters 2 different Times. The program then compares the two and returns true or false if T1 is bigger (this will then be displayed with boolalpha later on, but not worried about that right now just want to get it working).