|
|
|
|
|
by lutorm
4480 days ago
|
|
The crucial idea is that what's pointed to by those variables is also cleaned up. When a POD pointer goes out of scope, it doesn't help you that the pointer is deallocated, you need what's pointed to to be deallocated. Beyond pointers, it applies to many things that have a "C-style" API. Without RAII, anything that needs to be explicitly cleaned up needs to be monitored. For example, if you declare a pthread mutex, it doesn't help you that the mutex variable itself goes out of scope, because it's just a pointer and that will not clean up the actual mutex. And as people have said, without RAII it's impossible to write exception-safe code. |
|
Assuming that's hyperbole, I agree with the sentiment. It's possible to write exception safe code with try & catch - it's just almost as ugly as checking exit statuses and easier to miss something.