Why do we declare some arguments as constant? Is it because we do not expect the value of those constant arguments to change in the function?
Printable View
Why do we declare some arguments as constant? Is it because we do not expect the value of those constant arguments to change in the function?
You declare arguments constant when you don't want to be able to modify the types/objects being sent through the argument. For example, sometimes you wish to pass an object into a function by reference using a pointer/reference and you just want to get data from this object and not actually change it. This is often the case when you overload operators. It's more or less a safety precaution.Quote:
Originally posted by Sathyaish
Why do we declare some arguments as constant? Is it because we do not expect the value of those constant arguments to change in the function?
It also allows the compiler more leeway.
Thanks for the help. :-)