No suitable conversion function from "Time" to "int" exists

I'm working on a program using a lab I did a few weeks ago. I need to write the following operator overload functions then include a pre-written file (Optimeclient.cpp). Everything was working fine before I included the optimeclient file. Now I get the error: "IntelliSense: no suitable conversion function from "Time" to "int" exists". In lines 50 and 60 of the optimeclient file. Here are my 3 files

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  // This program calls the Time class.
#include <iostream>
#include <iomanip>
#include "time.h"
using namespace std;


Time::Time()           // Default constructer, initializes hour and minute to 00
{
	hour = 00;
	minute = 00;
}

Time::Time(int phour, int pmin)        //calls the setTime setter
{
	setTime(phour, pmin);
}
void Time::setTime(int phour, int pmin)    //Checks to see if the hour or minute are over 23/59 respectively, and sets them to 0 if they are
{
	if (phour < 0 || phour > 23 || pmin < 0 || pmin > 59)
	{
		hour = 0;         // Hour getting set to 0
		minute = 0;        // Minute getting set to 0
	}
	else
	{
		hour = phour;          // If the hour is between 0 and 23 it sets the hour to that time
		minute = pmin;        // If the minute is between 0 and 59 it sets the minute to that time 
	}
}

int Time::getHour()        // Function getHour, which returns hour as an int
{
	return hour;
}

void Time::addOneMinute()            //Function addOneMinute, which adds one minute
{
	minute++;                   //Minute being incremented

	if (minute == 60)            // If minute is 60 then minute goes back to 0 and hour gets incremented one
	{
		minute = 0;
		hour++;
		if (hour == 24)           //If hour is 24 it gets set back to 0
			hour = 0;
	}
}

void Time::showmealtime()                  // Function showmealtime, which displays breakfast, lunch, dinner, or No meal, depending on the time
{
	if (hour == 7)
		cout << "Breakfast" << endl;
	else if (hour == 12)
		cout << "Lunch" << endl;
	else if (hour == 17)
		cout << "Dinner" << endl;
	else
		cout << "No Meal" << endl;
}

void Time::display()                  // Functoin display, which displays the time
{
	
	cout << hour << ":" << setw(2) << setfill('0') << minute << endl;
}

Time Time::operator++()              //Overloads the++ operator.  The operation will add one minute to the time object.
{
	minute++;
	if (minute == 60)
	{
		minute = 00;
		hour++;
	}
	return *this
}

Time Time::operator+(int Rval){
	Time Tobj;
	int temphour;
	int tempmin;
	
	temphour = this.hour + Rval;
	tempmin = this.minute + Rval;


}

int Time::operator-(Time & Robj){
	Time Tobj;
	int temphour;
	int tempmin;

	temphour = this.hour - Robj;
	tempmin = this.minute - Robj;

	
}

bool Time::operator>(Time & Robj){
	if (this.hour > Robj.gethour()){
		return true;
	}
	else if (this.hour < Robj.gethour()){
		return false;
	}
	else if (this.hour == Robj.gethour()){
		if (this.minutes > Robj.getminutes()){
			return true;
		}
		else if (this.minutes < Robj.getminutes()){
			return false;
		}
		else{
			return false;
		}

	}
}

bool Time::operator==(Time & Robj){

	bool hourMatch, MinMatch;

	if (this.hour == Robj.gethour()){
		hourMatch = true;
	}
	if (this.minute == Robj.gethour()){
		MinMatch = true;
	}
return (hourMatch && MinMatch);

}

ostream &operator<< (ostream &output, Time & Robj){

	output << this.hours;
	output << ":" << this.minutes;

	return output;
}


istream &operator>> (istream &input, Time & Robj){
	
	in >> Robj.hours;
	in.ignore();
	in >> Robj.mintues;
	in.ignore();
	return in;

}



time.h
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
#include <iostream>
#include <iomanip>
using namespace std;

class Time
{
public:
	Time();
	Time(int phour, int pmin);
	void setTime(int phour, int pmin);
	int getHour();
	void addOneMinute();
	void showmealtime();
	void display();
	friend ostream &operator<< (ostream &output, Time & Robj);
	friend istream &operator>> (istream &input, Time & Robj);
	bool Time::operator==(Time & Robj);
	bool Time::operator>(Time & Robj);
	Time Time::operator-(Time & Robj);
	Time Time::operator+(int Rval);
	Time Time::operator++();
private:
	int hour;
	int minute;
};


optimeclient
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

#include <iostream>
#include <iomanip>
#include "time.h"
using namespace std;

int main()
{
	Time T1, T2, T3, T4;
	int diff;

	//========================  # 7 ==========================
	cout << "========  # 7 ===========" << endl;
	cout << "Enter the value for T1: ";
	cin >> T1;

	cout << "Enter the value for T2: ";
	cin >> T2;

	cout << "Enter the value for T3: ";
	cin >> T3;

	//========================  # 6 ==========================
	cout << "========  # 6 ===========" << endl;
	cout << "-------------------\n";
	cout << "Time 1 = " << T1 << endl;
	cout << "Time 2 = " << T2 << endl;
	cout << "Time 3 = " << T3 << endl;
	cout << "-------------------\n";
	//========================  # 1 ==========================
	cout << "========  # 1 ===========" << endl;
	T4 = ++T3;
	cout << "-------------------\n";
	cout << endl << "T4 = ++T3" << endl;
	cout << "Time 3 = " << T3 << endl;
	cout << "Time 4 = " << T4 << endl;
	cout << "-------------------\n";
	//========================  # 2 ==========================
	cout << "========  # 2 ===========" << endl;
	T4 = T2 + 59;
	cout << "-------------------\n";
	cout << "T4 = T2 + 59 " << endl;
	cout << "Time 2 = " << T2 << endl;
	cout << "Time 4 = " << T4 << endl;
	cout << "-------------------\n";


	//========================  # 3A ==========================
	cout << "========  # 3A ===========" << endl;
	diff = T2 - T1;
	cout << "-------------------\n";
	cout << "diff = T2 - T1; " << endl;
	cout << "Time 1 = " << T1 << endl;
	cout << "Time 2 = " << T2 << endl;
	cout << "diff = " << diff << endl;
	cout << "-------------------\n";

	//========================  # 3B ==========================
	cout << "========  # 3B ===========" << endl;
	diff = T1 - T2;
	cout << "-------------------\n";
	cout << "diff = T1 - T2; " << endl;
	cout << "Time 1 = " << T1 << endl;
	cout << "Time 2 = " << T2 << endl;
	cout << "diff = " << diff << endl;
	cout << "-------------------\n";

	//========================  # 4 ==========================
	cout << "========  # 4 ===========" << endl;
	cout << "-------------------\n";
	cout << T2 << " > " << T1 << endl;
	if (T2 > T1)
		cout << "True: Correct" << endl;
	else
		cout << "False: Not Correct" << endl;
	cout << "-------------------\n";


	//========================  # 5 ==========================
	cout << "-------------------\n";
	cout << "========  # 5 ===========" << endl;
	cout << T3 << " == " << T2 << endl;
	if (T3 == T2)
		cout << "True: Not Correct" << endl;
	else
		cout << "False: Correct" << endl;
	cout << "-------------------\n";

	system("pause");

	return 0;
}
Time Time::operator-(Time & Robj); Your operator- returns Time object, not int.
And you class does not define conversion operator either. So you cannot assign difference between classes to int.
Topic archived. No new replies allowed.