January 2019
Intermediate to advanced
512 pages
14h 5m
English
The name, RAII, refers to resources and not memory, and indeed the same approach is applicable to other resources. For each resource type, we need a special object, although generic programming and lambda expressions may help us to write less code (we will learn more on this in Chapter 11, ScopeGuard). The resource is acquired in the constructor and released in the destructor. Note that there are two slightly different flavors of RAII. The first option is the one we have already seen—the actual acquisition of the resource is at initialization, but outside of the constructor of the RAII object.
The constructor merely captures the handle (such as a pointer) that resulted from this acquisition. This was the case with ...