cannot convert parameter 1

I am having a bit of trouble. I dont understand what the compiler is trying to say. I have conducted reaserch, and added the const to two of my functions, but that did not even work.

Week1Lab_Benjamin Horne.cpp
1>Week1Lab_Benjamin Horne.cpp(45): error C2664: 'DayOfTheWeek::setDay' : cannot convert parameter 1 from 'DayOfTheWeek' to 'std::string'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>Week1Lab_Benjamin Horne.cpp(49): error C2664: 'DayOfTheWeek::setDay' : cannot convert parameter 1 from 'DayOfTheWeek' to 'std::string'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.17
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

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
#include <iostream>
using namespace std;
#include <string>

//DayOfTheWeek class definition

class DayOfTheWeek
{
public:
	// set the day of the week
	void setDay(string day1 )
	{
		day1 = day;
	} // end of function

	// function that gets the DayofTheWeek
	
	string getDay()const
	{
		return day; // returns the DayOfTheWeek
	} // end of getDayOfTheWeek function

	void printDay() const
	{
		cout << "The value of the " << getDay() << 
			"object is " << getDay() << endl;
	}
private:
	string day; // day is only availiable to DayOfTheWeek class functions
}; // end of DayOfTheWeek class definition


int main()
{
	DayOfTheWeek Monday;
	DayOfTheWeek Tuesday;
	
	
	
	Monday.setDay(Monday);
	Monday.getDay();
	Monday.printDay();

	Tuesday.setDay(Tuesday);
	Tuesday.getDay();
	Tuesday.printDay();

	return 0;
}
closed account (zb0S216C)
Lines 40, and 44 are where you're going wrong. You're trying to convert a string into a DayOfTheWeek structure, which doesn't make sense. Calling getDay( ) with solve this. For example:

1
2
3
4
5
6
int main( )
{
    Monday.setDay( Monday.getDay( ) );

    Tuesdat.setDay( Tuesday.getDay( ) );
}

Wazzak
Last edited on
I figured it out. I was not using quotations for my strings. .

Monday.setDay("Monday");

Tuesday.setDay("Tuesday");

Topic archived. No new replies allowed.