I have the following code, and I do not understand how we can give an object a parameter of type int? Also can some one please explain to me what the constructor does for the following code, and why it has arguments?
For Question #2, I know that a constructor initializes data members and is the first function to operate on an object , however I do not understand the purpose of line 6 , and does that relate to Question #1, seeing how an object can have 3 arguments?
I think I get it, the object passes 3 or less variables to the constructor where it validates the values passed (Checks if statement then initializes the private variables accordingly) , and the parameter values for the constructor : h , m and s are all equal to 0 thanks to line 6? Is this correct?
Those integer arguments are being passed to the constructor for the class, initializing the objects appropriately.
sakonpure6 wrote:
For Question #2, I know that a constructor initializes data members and is the first function to operate on an object , however I do not understand the purpose of line 6 , and does that relate to Question #1, seeing how an object can have 3 arguments?
Line 6 declares that there is a constructor which takes three arguments, but it also gives default values for all three parameters, so this constructor also counts as the default constructor since it may be invoked with no explicit arguments. The compiler just passes in the default arguments for you.
sakonpure6 wrote:
I think I get it, the object passes 3 or less variables to the constructor where it validates the values passed (Checks if statement then initializes the private variables accordingly) , and the parameter values for the constructor : h , m and s are all equal to 0 thanks to line 6? Is this correct?
The = 0 on line 6 are just the default values, and if you pass a value for that parameter the = 0 is ignored.