I am trying to call a programmer defined default constructor inside of an overloaded 3 argument constructor. When I create an instance of my Date class, I pass it 3 arguments, the overloaded constructor then passes those params to a validate function. If the return value is false, I want to call my default constructor inside my overloaded constructor, but I get garbage values.
1/-858993460/-858993460
Is it okay to call constructor within constructor?
//test.cpp
int main ()
{
date d1(m, d, y);
}
//header
class Date {
private:
string month;
int day, year;
bool validateDate(string, int, int);
//Date();
public:
Date();
Date(string, int, int);
void print(DateFormat type);
};
//implmentation
Date::Date() : month("January"), day(1), year(2001) { cout << "INSIDE CONST" << endl; } //default constructor
Date::Date(string m, int d, int y) //overloaded constructor
{
if (!validateDate(m, d, y))
{
cout << "IF FALSE" << endl;
//Date(); //This doesn't work
Date d1; //This doesn't work as well
}
else
{
month = m;
day = d;
year = y;
cout << "MONTH IS :" << month << " DAY IS: " << day << " YEAR IS: " << year << endl;
}
}