C++ Operator overloading (>>) errors

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.

Heres the relevant code:

Main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include "Time.h"

using namespace std;

int main() {

    int hour1, minute1, second1, hour2, minute2, second2;

    cout << "Enter T1 (hh, mm, ss): ";
    cin >> hour1;
    cin >> minute1;
    cin >> second1;
    cout <<endl;

    cout << "Enter T2 (hh, mm, ss): ";
    cin >> hour2;
    cin >> minute2;
    cin >> second2;
    cout <<endl;

   Time T1(hour1, minute1, second1);
   Time T2(hour2, minute2, second2);

   if(T1 > T2){
   cout << "T1 is bigger than T2" <<endl;
   }
   else {
    cout <<"Something wrong" <<endl;
   }
   return 0;
}


Time.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef TIME_H
#define TIME_H

class Time
{
    public:
        Time();
        Time (int h, int m, int s);

        void displayTime();


        bool operator>(const Time& other);


    private:
        int hours;
        int minutes;
        int seconds;
};

#endif // TIME_H 


and Time.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include "Time.h"

using namespace 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;
}

bool operator>(const Time &other){ //THIS IS WHERE THE ERROR IS SHOWING
if (hours > other.hours){
    return true;
}
if (hours == other.hours && minutes > other.minutes){
    return true;
}
if (minutes == other.minutes && seconds > other.seconds){
    return true;
}
return false;
}


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).

Thank you for the help.
Last edited on
Your operator> function is missing a Time::

bool Time::operator>(const Time &other){ //THIS IS WHERE THE ERROR IS SHOWING
@Repeater
Ffs.... thanks man. Such a silly mistake.
Topic archived. No new replies allowed.