Chapter 9. Copying, Initialization, and Assignment

C++ code can be short, precise, and clear. For example, to append a string to another string, you can use s1 += s2, whereas a C programmer would have to use strcat(p1,p2), which is not only less obvious but can be a problem if the buffer p1 is too small to hold all the characters. Similarly, the simple C++ assignment s1 = s2 takes care of any copying and reallocation that is necessary. Not everyone who drives cars needs to learn about carburetors, but you are a better car owner if you know that your car contains fuel, water, and oil systems rather than straw and oats. This chapter gives a quick tour under the hood of the C++ object model: what its hidden costs are, and what its weak points are. ...

Get C++ By Example: UnderC Learning Edition 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.