Beginner Lost With Program

I'm a total beginner with only traces of memory from C language class. Right now I'm working on a calender project and I don't know what is wrong with it because it keeps giving me these 3 errors that all pretty much say,

"'Date::Date(char,int,int)' : cannot convert parameter 1 from 'const char [6]' to 'char'"


Here is the code from my header file:
class Date
{
private:
char month;
int day,year;

public:
Date(char sm, int sd, int sy);

void setmonth(char sm);
void setday(int sd);
void setyear(int sy);


char getmonth();
int getday();
int getyear();


void display();

};


Now the code from my source file:

#include <iostream>

using namespace std;

#include "Date.h"

Date::Date(char sm, int sd, int sy)
{
month = sm;
day = sd;
year = sy;


}

void Date::setmonth(char sm)
{
month = sm;
}

void Date::setday(int sd)
{
day = sd;
}


void Date::setyear(int sy)
{
year = sy;
}

char Date::getmonth()
{
return month;
}

int Date::getday()
{
return day;
}

int Date::getyear()
{
return year;
}

void Date::display()
{
cout << month << day << "," << year << endl;

}

and lastly the code from my source file with the testdata :
#include "Date.h"

int main()
{
Date d1("April",3,2009);
Date d2("January",2,2006);
Date d3("August",4,2002);

d3.display();
d2.display();
d1.display();

return 0;
}

Now I can get my year and date to display, but not the name of my months. what could I be doing wrong???




Declaration: Date(char sm, int sd, int sy);
Arguments passed: Date d1("April",3,2009);
Error message: Date::Date(char,int,int)' : cannot convert parameter 1 from 'const char [6]' to 'char'
It's just what the error says, the parameter is a single char, you are passing a sequence of characters.
Declare 'sm' as std::string -after you #included <string> -
Last edited on
Thank you VERY much for the quick reply. Please bear with me on my additional questions as I really am this clueless.

Does this mean that I do not need to make any changes to my header file but I do need to apply some to the source file without the test data?

Am I supposed to change Date(char sm, int sd, int sy); to Date(std::string, int sd, int sy);??? Kind of confused on that part of your reply...
You need to change the header file and the source file in which you defined Date::Date so that the 1st parameter is a std::string instead of a char
Topic archived. No new replies allowed.