overloaded member function not found

Functions continue to give me problems, I am unable to see the issues any help would be appreciated.

1>c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(28) : error C2511: 'void DayOfTheWeek::printDay(void) const' : overloaded member function not found in 'DayOfTheWeek'
1> c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(11) : see declaration of 'DayOfTheWeek'
1>c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(56) : error C2440: '=' : cannot convert from 'std::string' to 'int'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(57) : error C2562: 'DayOfTheWeek::setDay' : 'void' function returning a value
1> c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(14) : see declaration of 'DayOfTheWeek::setDay'
1>c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(63) : error C2511: 'std::string DayOfTheWeek::getDay(void) const' : overloaded member function not found in 'DayOfTheWeek'
1> c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(11) : see declaration of 'DayOfTheWeek'
1>c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(68) : error C2511: 'std::string DayOfTheWeek::plusOneDay(int)' : overloaded member function not found in 'DayOfTheWeek'
1> c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(11) : see declaration of 'DayOfTheWeek'
1>c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(74) : error C2511: 'std::string DayOfTheWeek::minusOneDay(int)' : overloaded member function not found in 'DayOfTheWeek'
1> c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(11) : see declaration of 'DayOfTheWeek'
1>c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(80) : error C2511: 'std::string DayOfTheWeek::addDays(int)' : overloaded member function not found in 'DayOfTheWeek'
1> c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(11) : see declaration of 'DayOfTheWeek'
1>c:\users\ben\documents\visual studio 2008\projects\week2lab_benjamin_horne\week2lab_benjamin_horne\dayoftheweek.cpp(117) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)



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
#include <iostream>
#include <string>


using namespace std;



class DayOfTheWeek
{
public:

	void setDay(string);
	void printDay();
	string getDay();
	string plusOneDay();
	string minusOneDay();
	string addDays();

private:
	int day;
	int toNumber(string);
	string toName(int);
};

void DayOfTheWeek::printDay()const
{
		cout << "The value of the " << day << " object is "; 
		if (day == "Monday")
			cout << "Mon" << endl;
	
		if (day == "Tuesday")
			cout << "Tues" << endl;

		if (day == "Wednesday")
			cout << "Wed" << endl;

		if (day == "Thursday")
			cout << "Thur" << endl;

		if (day == "Friday")
			cout << "Fri" << endl;

		if (day == "Saturday")
			cout << "Sat" << endl;

		if (day == "Sunday")
			cout << "Sun" << endl;

}

void DayOfTheWeek::setDay(string d)
{

day = d;
return toNumber(d);

}


string DayOfTheWeek::getDay()const
{
	return day;
}

string DayOfTheWeek::plusOneDay(int add)
{
	int add = day + 1;
	return toName(add);
}

string DayOfTheWeek::minusOneDay(int minus)
{
	int minus = day - 1;
	return toName(minus)
}

string DayOfTheWeek::addDays(int incr)
{
	int idx = day + incr;
	if (idx < 0) idx += 7;
	return toName(idx);
}

int DayOfTheWeek::toNumber(string name)
{
	if (name == "Monday") return 0;
	if (name == "Tuesday") return 1;
	if (name == "Wedensday") return 2;
	if (name == "Thursday") return 3;
	if (name == "Friday") return 4;
	if (name == "Saturday") return 5;
	if (name == "Sunday") return 6;
}

string DayOfTheWeek::toName(int idx)
{
	idx = idx % 7;
	switch (idx)
	{
		case 0: return "Monday"; break;
		case 1: return "Tuesday"; break;
		case 2: return "Wednesday"; break;
		case 3: return "Thursday"; break;
		case 4: return "Friday"; break;
		case 5: return "Saturday"; break;
		case 6: return "Sunday"; break;
	}
}

int main()
{
	DayOfTheWeek monday;
	monday.setDay("Monday");

	cout << "The value of the Monday object is " << monday.printDay()<< endl;

return 0;
}
Last edited on
one of the problems is :
you are using day as string although it is defined to be an int.

like in the function setDay(string d).

i think it should be something like :
1
2
3
4
void DayOfTheWeek::setDay(string d)
{
   day=toNumber(d);
}

correct this and other function with that mistake and try again.
hope this helps.
Last edited on
Line 14 must be void printDay() const; // Note const
Line 15 must be string getDay() const; // Note const
Line 18 must be string addDays(int incr); // Note int incr
Line 66 must be string DayOfTheWeek::plusOneDay() // Note _no_ int add
Line 73 must be string DayOfTheWeek::minusOneDay() // Note _no_ int minus

Line 116: printDay() is already doing the cout so no further cout is needed / is wrong here so: monday.printDay();
Last edited on
in printDay()

you are trying to check day == "sunday" , "monday" ...

again comparing an integer with a string.

should be :

toName (day) == "monday" ...

or :

day == toNumber("monday")...
To all; Thanks. I am beginning to understand what the course has been explianing, calling on the data members to manipulate the private variables, but what I am not understanding is the use of the utility functions in regards to the passing of data.

My last error is a take 0 argument error. I have tried everthing from adding a varible to adding a variable and an &, but still no movement. I have tried in both the get day function, which produces more erros and in the toNumber function.

1
2
3
4
5
string DayOfTheWeek::getDay()
{
	
	return toNumber();
}
If you write getDay returning a string then you want obviously the name, so:

1
2
3
4
string DayOfTheWeek::getDay()
{
	return toName(day);
}
I have started to see. However now I

error C2662: 'DayOfTheWeek::toName' : cannot convert 'this' pointer from 'const DayOfTheWeek' to 'DayOfTheWeek &'

for

1
2
3
4
5
string DayOfTheWeek::getDay()const
{
	int temp = day;
	return toName(temp);
}

getDay() is const, but toName is not. You can't call non-const member functions inside const ones, for obvious reasons.
should I turn toName into a constant?
It has compiled, however I continue to get -858993460 in variable day. Can someone explain?

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
#include <iostream>
#include <string>


using namespace std;



class DayOfTheWeek
{
public:

	void setDay(string);
	void printDay();
	string getDay()const;
	string plusOneDay();
	string minusOneDay();
	string addDays(int incr);

private:
	
	int day;
	int toNumber(string);
	string toName(int)const;


};

void DayOfTheWeek::printDay()
{
		cout << "The value of the " << day << " object is "; 
		if (getDay() == "Monday")
			cout << "Mon" << endl;
	
		if (getDay() == "Tuesday")
			cout << "Tues" << endl;

		if (getDay() == "Wednesday")
			cout << "Wed" << endl;

		if (getDay() == "Thursday")
			cout << "Thur" << endl;

		if (getDay() == "Friday")
			cout << "Fri" << endl;

		if (getDay() == "Saturday")
			cout << "Sat" << endl;

		if (getDay() == "Sunday")
			cout << "Sun" << endl;
}

void DayOfTheWeek::setDay(string d)
{
int newDay = 0;
newDay = day;
newDay = toNumber(d);

}


string DayOfTheWeek::getDay()const
{
	
	return toName(day);
}

string DayOfTheWeek::plusOneDay()
{
	int add = day + 1;
	return toName(add);
}

string DayOfTheWeek::minusOneDay()
{
	int minus = day - 1;
	return toName(minus);
}

string DayOfTheWeek::addDays(int incr)
{
	int idx = day + incr;
	if (idx < 0) idx += 7;
	return toName(idx);
}

int DayOfTheWeek::toNumber(string name)
{
	if (name == "Monday") return 0;
	if (name == "Tuesday") return 1;
	if (name == "Wedensday") return 2;
	if (name == "Thursday") return 3;
	if (name == "Friday") return 4;
	if (name == "Saturday") return 5;
	if (name == "Sunday") return 6;
}

string DayOfTheWeek::toName(int idx) const
{
	idx = idx % 7;
	switch (idx)
	{
		case 0: return "Monday"; break;
		case 1: return "Tuesday"; break;
		case 2: return "Wednesday"; break;
		case 3: return "Thursday"; break;
		case 4: return "Friday"; break;
		case 5: return "Saturday"; break;
		case 6: return "Sunday"; break;
	}
}

int main()
{
	DayOfTheWeek monday;
	monday.setDay("Monday");

	monday.printDay();

	
	monday.addDays (6);
	monday.getDay();
	monday.printDay();

return 0;
}
setDay doesn't actually modify "day", it just creates a temporary variable, does some stuff, and then destroys it.
Now it doesnt add. From what I see I added 2 to addDays, which pulls down the varible day and adds the increment and after a check sends it to toName. While in toName it is modulized, which is confusing me, becasue that should equal case five, but I am somehow hoping for case 2, but regardless it should be switched and returned. THis is where I am confuesed how am i bringing back a string when I sent in an interger. All the while the addDays function never added any days.

Sorry to bug but these things just arn't being taught in class.

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
#include <iostream>
#include <string>


using namespace std;



class DayOfTheWeek
{
public:

	void setDay(string);
	void printDay();
	string getDay()const;
	string plusOneDay();
	string minusOneDay();
	string addDays(int incr);

private:
	string temp;
	int day;
	int toNumber(string);
	string toName(int)const;


};

void DayOfTheWeek::printDay()
{
		cout << "The value of the " << day << " object is "; 
		if (getDay() == "Monday")
			cout << "Mon" << endl;
	
		if (getDay() == "Tuesday")
			cout << "Tues" << endl;

		if (getDay() == "Wednesday")
			cout << "Wed" << endl;

		if (getDay() == "Thursday")
			cout << "Thur" << endl;

		if (getDay() == "Friday")
			cout << "Fri" << endl;

		if (getDay() == "Saturday")
			cout << "Sat" << endl;

		if (getDay() == "Sunday")
			cout << "Sun" << endl;
}

void DayOfTheWeek::setDay(string d)
{
int newDay;
newDay = day;
newDay = toNumber(d);
day = newDay;

}


string DayOfTheWeek::getDay()const
{
	 
	return toName(day);
	
	
}

string DayOfTheWeek::plusOneDay()
{
	int add = day + 1;
	return toName(add);
}

string DayOfTheWeek::minusOneDay()
{
	int minus = day - 1;
	return toName(minus);
}

string DayOfTheWeek::addDays(int incr)
{
	int idx = day + incr;
	if (idx < 0) idx += 7;
	return toName(idx);
}

int DayOfTheWeek::toNumber(string name)
{
	if (name == "Monday") return 0;
	if (name == "Tuesday") return 1;
	if (name == "Wedensday") return 2;
	if (name == "Thursday") return 3;
	if (name == "Friday") return 4;
	if (name == "Saturday") return 5;
	if (name == "Sunday") return 6;
}

string DayOfTheWeek::toName(int idx) const
{
	idx = idx % 7;
	switch (idx)
	{
		case 0: return "Monday"; break;
		case 1: return "Tuesday"; break;
		case 2: return "Wednesday"; break;
		case 3: return "Thursday"; break;
		case 4: return "Friday"; break;
		case 5: return "Saturday"; break;
		case 6: return "Sunday"; break;
	}
}

int main()
{
	DayOfTheWeek monday;
	monday.setDay("Monday");

	monday.printDay();

	
	monday.addDays (2);
	monday.getDay();
	monday.printDay();

return 0;
}


closed account (zb0S216C)
Now it doesnt add.
You never assign the member day of DayOfTheWeek a value. So, on line 86, idx receives the value of 2 when monday.addDays (2); is called.

Edit:
On lines 56, and 57, member day still remains without a value. newDay is not given a value which, after the assignment on line 57, member day still remains without a value.

Sorry on my behalf. Never mind.
Last edited on
Topic archived. No new replies allowed.