creating a header file problems
ok i attempted to create a header file by copying exactly what was in the book...and i got some errors so here is my header file and then my actual program using it:
Code:
class Date
{
public:
//intializes variables
Date();
//assigns program values to variables
void assigndate(char,char,char);
//returns formatted date
char getdate();
private:
char month[50];
char day[50];
char year[50];
};
//implentation section
Date::Date()
{
//constructor
month = "";
day = "";
year = "";
}//end of default constructor
void Date::assigndate(char m[50],char d[50],char y[50])
{
month = m;
day = d;
year = y;
}//end of assigndate function
char Date::getdate()
{
return month + "/" + day + "/" + year;
}// end of getdate function
include <iostream>
using namespace std;
#include <Date.h>
int main()
{
//create object
Date dateobj;
//declare variables
char hiremonth[50] = "";
char hireday[50] = "";
char hireyear[50] = "";
//get month,day, and year
cout << "Enter the month: ";
cin.get(hiremonth,50);
cin.get();
cout << endl << "Enter the day: ";
cin.get(hireday,50);
cin.get();
cout << endl << "Enter the year: ";
cin.get(hireyear,50);
cin.get();
//set the date
dateobj.assigndate(hiremonth,hireday,hireyear);
//display the date
cout << "\nEMployee hire date " << dateobj.getdate() << endl;
return 0;
}//end main function
and now the errors:
Compiling...
CLASStest1.cpp
c:\program files\microsoft visual studio\vc98\include\date.h(20) : error C2440: '=' : cannot convert from 'char [1]' to 'char [50]'
There is no context in which this conversion is possible
c:\program files\microsoft visual studio\vc98\include\date.h(21) : error C2440: '=' : cannot convert from 'char [1]' to 'char [50]'
There is no context in which this conversion is possible
c:\program files\microsoft visual studio\vc98\include\date.h(22) : error C2440: '=' : cannot convert from 'char [1]' to 'char [50]'
There is no context in which this conversion is possible
c:\program files\microsoft visual studio\vc98\include\date.h(26) : error C2511: 'assigndate' : overloaded member function 'void (char [],char [],char [])' not found in 'Date'
c:\program files\microsoft visual studio\vc98\include\date.h(2) : see declaration of 'Date'
c:\program files\microsoft visual studio\vc98\include\date.h(34) : error C2110: cannot add two pointers
c:\documents and settings\evelyn\desktop\adam\c++\classtest1.cpp(26) : error C2664: 'assigndate' : cannot convert parameter 1 from 'char [50]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
CLASStest1.obj - 6 error(s), 0 warning(s)
ive never done this before so im not really sure what these errors mean any help would be appreciated thanx