Another Constructor Example
// Imagine we wanted to create a class that could hold a date.
// We might give it 5 constructors, to allow the user to specify
// any part of the date, and assume that any unspecified part
// should be the current year, month, or day. (Note, the code
// to implement the constructors is not shown)
int year_p, month_p, day_p;
date(); // Constructor that takes no args
date(int day); // Overloaded constructor (takes one arg)
date(int month, int day); // Another overloaded constructor
date(int year, int month, int day); // And another
date(char *d); // A function that parses a date string
date today; // date() constructor is called
date a(27), date b(2, 24), date c(1994, 1, 30); // all ok
date d(“June 1st”); // Ok: Uses last constructor
date e(“June 1st”, 1993); // Illegal; we have no constructor
// that takes (char *, int), but we could write one
date f(1997); // Incorrect -- but the compiler won’t tell us!