Immutable object: Difference between revisions

Content deleted Content added
m linking
Line 92:
 
=== C++ ===
In C++, a [[const-correctness|const-correct]] implementation of <code>Cart</code> would allow the user to declare new instances of the class as either <code>const</code> (immutable) or mutable, as desired, by providing two different versions of the <code>getItemsitems()</code> method. (Notice that in C++ it is not necessary — and in fact impossible — to provide a specialized constructor for <code>const</code> instances.)
 
<syntaxhighlight lang="cpp">