Quantcast
Channel: Does C++ support 'finally' blocks? (And what's this 'RAII' I keep hearing about?) - Stack Overflow
Viewing all articles
Browse latest Browse all 17

Answer by Michael Burr for Does C++ support 'finally' blocks? (And what's this 'RAII' I keep hearing about?)

$
0
0

Beyond making clean up easy with stack-based objects, RAII is also useful because the same 'automatic' clean up occurs when the object is a member of another class. When the owning class is destructed, the resource managed by the RAII class gets cleaned up because the dtor for that class gets called as a result.

This means that when you reach RAII nirvana and all members in a class use RAII (like smart pointers), you can get away with a very simple (maybe even default) dtor for the owner class since it doesn't need to manually manage its member resource lifetimes.


Viewing all articles
Browse latest Browse all 17

Trending Articles