June 2025
Intermediate to advanced
1093 pages
33h 24m
English
RAII means that when creating an object—a resource—its initialization is also done. In C++, this happens in the constructor. It is important to always leave a valid object when exiting the constructor.
This means, in particular, that even an error must not leave an invalid object lying around. If an error occurs during the initialization of the object in the constructor, you must not leave half-created data structures lying around or still blocking resources. Resource can mean many things here, such as a pointer to reserved memory, an open file, or a lock for mutual exclusion of multiple processes.
In case of an error, the constructor should be exited with an exception so that higher levels can ...
Read now
Unlock full access