2.1 Introduction and Objectives
In this chapter we introduce new syntax and functionality in C++ that adds value to the language as a worthy successor to C++03. We discuss the features that promote the run-time efficiency, reliability and usability of code, namely:
- Automatic memory management: avoiding memory disasters that the use of raw pointers can lead to.
- Move semantics: allowing the compiler to replace expensive copying operations with less expensive move operations. In some cases, move semantics are the only options as some classes do not support copy constructors. Typical examples are smart pointers and classes for multithreading and multitasking.
- New fundamental data types.
The features in this chapter are crucial as they represent best practices when writing C++ code. For this reason we introduce these features early on in the book. We also strongly recommend that you do the exercises in this chapter to become acquainted with the new features as soon as possible.
2.2 The C++ Smart Pointers
In this chapter we first introduce (as background) the Boost Smart Pointer library that makes object lifecycle management easier when compared to using the new and delete operators in C++. In particular, the responsibility for removing objects from memory is taken from the developer's shoulders. To this end, we discuss a number of classes that improve the reliability of C++ code. The two most important classes are:
- Scoped pointer: ensures ...