Assignment of Responsibility
Although it's actually possible to get the effect of two independent strings without the extra work of allocating memory and copying data every time an assignment is done, the mechanisms needed to do that are beyond the scope of this book.[13] By far the easiest way to have the effect of two independent strings is to actually make another copy of a string's data whenever we copy the string, and that's how we'll do it here. The results will be as indicated in Figure 7.12.
[13] We'll see how to implement a similar feature in another context when we get back to the discussion of inventory control later in the book.
Figure 7.12. strings n and sin memory after custom =
With this arrangement, a change to one of the ...
Get Learning to Program in C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.