Chapter 5. Initialization
The semantics of initialization in C++ are subtle, complex, and important.
The reasons behind this complexity are not frivolous. Much of programming in C++ consists of using classes to design abstract data types. Essentially, we extend the base C++ language with new data types integrated into the rest of the type system. On one hand, we're engaged in programming-language design to produce usable, integrated types. On the other hand, we're engaged in translator design, in that we must convince the compiler to translate our implementations of these abstract data types efficiently. The details of initialization and copying of class objects are essential to efficient, production-quality use of data abstraction.
Equally important to efficiency, of course, is correctness. Unfamiliarity with the necessarily complex semantics of initialization in C++ can lead to misuse.
In this chapter, we'll examine issues of implementing initialization as well as how to convince the compiler to optimize user-defined initialization and copy operations. We'll also examine several common problems associated with misunderstanding the semantics of initialization.
|