O'Reilly logo

Imperfect C++ Practical Solutions for Real-Life Programming by Matthew Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required