Content deleted Content added
m →C/C++ Syntax: to "C++ syntax" |
|||
Line 7:
A [[class method]] can be declared as <code>const</code>, indicating that calling that method does not change the object. Such <code>const</code> methods can only call other <code>const</code> methods but cannot assign [[field (computer science)|member variables]]. (In C++, a member variable can be declared as <code>mutable</code>, indicating that a <code>const</code> method can change its value. Mutable member variables can be used for [[cache|caching]] and [[reference counting]], where the logical meaning of the object is unchanged, but the object is not physically constant since its bitwise representation may change.)
==
In C++ all data types, including those defined by the user, can be declared <code>const</code>, and all objects should be unless they need to be modified. Such proactive use of <code>const</code> makes values "easier to understand, track, and reason about,"<sup>[[#Footnotes|1]]</sup> and thus, it increases the readability and comprehensibility of code and makes working in teams and maintaining code simpler because it communicates something about a value's intended use.
|