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.

In this chapter you will learn

  • The difference between initialization and assignment

  • What memberwise copying is and why it isn't always appropriate

  • How to customize initialization behavior

  • About value semantics, as opposed to pointer semantics

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.59.145