What is Const Object?

  • Making variables const ensures that their values are not accidentally changed.
  • Just like the built-in data types (int, double, char, etc…), class objects can be made const by using the const keyword.
  • Once a const class object has been initialized via constructor, any attempt to modify the member variables of the object is disallowed, as it would violate the constness of the object.
  • This includes both changing member variables directly (if they are public), or calling member functions that sets the value of member variables:


Post a Comment

Previous Post Next Post