Finished reading ch 9 of Programming Principals but I have a question. The part where a default constructor is defined for a class called Date. The constructor initialized three variables that are located in the private sphere of the Date object (year, month, and day). At any rate, these three variables since they are private members, their values are otherwise accessed through acessor methods. During default construction this same method containing a static default value, separately calls each one of these public acessor methods and the return type of this culprit in question is a Date object. The way that it is written in the default construction, this method calls each of the three acessor methods in turn so that all three Date elements are initialized. This looked highly unusual. Why can a method call another method?
Code:
Date::Date()
:y{default_date().year()},
:m{default_date().month(),
:d{default_date().day()}
{
}
Also
Code:
const Date& default_date() {
static Date dd {2001, Month::Jan, 1};
return dd;
}