CppCon 2019 has ended
Back To Schedule
Tuesday, September 17 • 09:00 - 10:00
Back to Basics: RAII and the Rule of Zero

Log in to save this to your schedule, view media, leave feedback and see who's attending!

RAII, or "Resource Allocation is Initialization," is one of the cornerstones of C++. What is it, why is it important, and how do we use it in our own code?

Small resource-managing classes should follow the Rule of Three (or Five); larger, composite, business-logic classes should follow the Rule of Zero. We'll explain these "Rules," what they mean, and how their consistent application helps us avoid resource leaks and double-frees. We'll also show how thinking about the Rule of Three can lead to a consistent guideline for polymorphic classes with virtual destructors.

Finally, we'll touch on the "copy and swap" idiom, which in many cases can reduce the Rule of Five to the Rule of Four (and a Half).

Attendees will leave this session with a clearer understanding of resource management in C++.

avatar for Arthur O'Dwyer

Arthur O'Dwyer

C++ Trainer
Arthur O'Dwyer is the author of "Mastering the C++17 STL" (Packt 2017) and of professional training courses such as "Intro to C++," "Classic STL: Algorithms, Containers, Iterators," and "The STL From Scratch." (Ask me about training your new hires!) Arthur is occasionally active on... Read More →

Tuesday September 17, 2019 09:00 - 10:00 MDT
Aurora A
  Back to Basics