Book Image

C++ Fundamentals

By : Brent Arnold
Book Image

C++ Fundamentals

By: Brent Arnold

Overview of this book

C++ has come a long way and is now adopted in several contexts. Its key strengths are its software infrastructure and resource-constrained applications, including desktop applications, servers, and performance-critical applications, not to forget its importance in game programming. Despite its strengths in these areas, beginners usually tend to shy away from learning the language because of its steep learning curve. The main mission of this book is to make you familiar and comfortable with C++. You will finish the book not only being able to write your own code, but more importantly, you will be able to read other projects. It is only by being able to read others' code that you will progress from a beginner to an advanced programmer. This book is the first step in that progression.
Table of Contents (6 chapters)
Chapter 3
Classes
Content Locked
Section 5
Resource Acquisition is Initialization
Resource Acquisition Is Initialization (RAII), is a programming idiom that is used to manage the life cycle of a resource automatically by binding it to the lifetime of an object. This can be achieved through smart use of the constructor and destructor of an object. The former acquires the resource, while the latter realizes it. The constructor is allowed through, for example, when a resource cannot be acquired, while the destructor never throws exceptions. It is a good practice to operate on a resource of a RAII class when its usage involves open()/close(), lock()/unlock(), start()/stop(), or init()/destroy() function calls.