Reputation: 3
My instructor requires us to fill out the constructors associated with these prototypes:
YearToMonth(short years=0);
YearToMonth(short years, short months);
My question is: with the 1 parameter constructor, will the value passed in always = 0? I've never seen a function that assigned value to a parameter before. Seems kinda strange to require input when the value is just going to be set to zero but then I wasn't given any documentation on this class so I don't really know what it does yet.
Upvotes: 0
Views: 43
Reputation: 3260
It's default value for the parameter. if you pass your own value to it, it will be set to your value.
Upvotes: 0
Reputation: 304112
It's a default argument. Its effect is to provide a default value if the user doesn't explicitly specify one. For example:
YearToMonth(); // calls YearToMonth(short ); with years=0
YearToMonth(2); // calls YearToMonth(short ); with years=2
Upvotes: 2