This is the prototype I was provided with for my Person constructor:
Person(const char * their_name, const char * email, int day, int month, int year);
In making my constructor I have tried to use base member intialization, but I am having issues, this is what my constructor looks like:
Person(const char * their_name, const char * email, int day, int month, int year): name(0), email_address(0), aDay(1), aMonth(1), aYear(2000){
char * temp = new char[strlen(their_name) + 1];
strcpy_s(temp, strlen(their_name) + 1, their_name);
name = temp;
email_address = new char[strlen(email) + 1];
strcpy_s(email_address, strlen(email) + 1, email);
/*
int aDay = day;
int aMonth = month;
int aYear = year;
*/
cout << "\nPerson(...) CREATING: ";
printOn(cout);
}
My compiler is having issues with saying aDay(1), aMonth(1), aYear(2000). If this is not how I am supposed to initialize these three ints, how am I supposed to?
This is my Date class that have a constructor that takes 3 ints...
public:
//Notice there is no default constructor
Date(int d, int m, int y) {day = d; month = m; year = y;}
void printOn(ostream & out) const {out << day <<"/" << month << "/" << year;}
~Date(){
cout<<"Deleting Date: "<<day<<"/"<<month<<"/"<<year;
}
private:
int day, month, year;
};
ostream & operator<<(ostream & ostr, const Date & d) {
d.printOn(ostr);
return ostr;
}
The error with my person constructor is that there is no default constructor for Date (but I am not supposed to have one)
Thanks!