struct Date {
int d, m , y;
void init_date(Date& d, int, int, int);
void add_year(int n);
void add_month(Date& d, int n);
void add_day(Date& d, int n);
}
Date my_birthday;
void f()
{
Date today;
today.init(16, 10, 1996);
my_birtday.init(30, 12, 1950);
Date tomorrow = today;
tomorrow.add_day(1);
// ...
}
Question A: In the above snippet, isn't: Date tomorrow = today; wrong in the sense that there is no "copy constructor" provided within struct Date. I know there is a "default constructor" auto generated by the compiler - but I'm not sure what exactly it does or how exactly it works (it can call the default constructor of a member-class, but it doesn't initialize: int i; and stuff like that). Could someone clarify how the compiler's default constructor works?
Question B: We would have to insert something like this: const Date& Date(const Date& r); correct? But, the above constructor implies we pass it one argument (a reference to "today"). So, how does an "initialization": "Date tomorrow = today" translate to a function call: Date tomorrow(today); Is there any "magic" happening here??
Question C: What is the format of the operator, new? Stroustrup uses it in different ways but there's no clear listing of all its uses. So far I could find: new ; new Type[size]; new Type(size); new Type; Is this listed/given anywhere? Have I missed out any?