Why does C++ make objects unmodifiable by default?
This article mainly explains why C++ makes objects unmodifiable by default. Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn why C++ makes objects unmodifiable by default.
Con.1: make objects unmodifiable by default
Reason (reason)
Immutable objects are easier to reason about, so make objects non-const only when there is a need to change their value. Prevents accidental or hard-to-notice change of value.
Immutable objects are easier to understand, so objects are defined as non-constants only when there is a need for change. Prevent accidental or imperceptible modification of the value of the object.
Example (sample)
For (const int i: C) cout