Chapter 6. Scoping Classes
In section 3.5 we looked at the definition of Resource Acquisition Is Initialization (RAII), and in this chapter we're going to demonstrate some of the different ways in which it can be applied.
RAII is singularly potent when it comes to resource management. We expect that when a vector<string> goes out of scope, its destructor is called and it releases its contents. As part of this process, all the contained string instances are also destroyed and release their resources, after which the memory block that the vector used to store the string instances is released back to the free store. You get all that functionality just by typing a }.
The treatment here is pure RAII: a scoping instance acquires a resource in its constructor ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access