0
What is const function and const object?
2 Réponses
+ 3
A const object can't have any of its member variables modified. It's as if you've applied const to all of its member variables.
A const function is a promise to the compiler that the function will not change the state of the object (or, in other words, it won't change any of the member variables).
When you have a const object, you can only call its const functions. Trying to call any other member functions will give you a compiler error.
The point of using const objects is so you can pass them into functions by reference while assuring the user that the object passed in will not be modified. This also keeps you from accidentally modifying it where you shouldn't be.
0
As I know variables can get different values but constants (like pi) never can get a different value