+ 1
Please explain object arguments
I have this code that copied from the C++ lesson: https://code.sololearn.com/cY6G8MNc31SH/?ref=app I am basicly wondering in the Person constructor they made an object called b and then replaced it with it bd. Now, why did they make that object and then just replace it ? Is that nessesary to do ? If you could explain what is going on in the Person constructor that would be greatly appreciated Any ways, thank you for your feedback
3 Respuestas
+ 2
You need to store the value that is passed to a function or a constructor like you just can't use them directly. So, they are taking another variable to store this value. And also the variable bd is private which makes it more secure.
+ 1
So what happening is that using an object in the paramenter it is telling the program that " Hey a object is coming though here". Is that correct?
Thank you
+ 1
The object wasn't replaced. When you define a function, the variable name you use for the function is called a parameter. Basically, it is the placeholder name for the variable that you will eventually pass into the function later. This goes for constructors as well. In this code, you could have passed any Birthday object into the Person constructor, whether it was named bd or even 'birthday_object'. And yes, you are basically telling the program that an object is coming through there by saying 'Birthday b', so the program knows a birthday object will be passed into the Person constructor. Hope that helps