Hacker News new | past | comments | ask | show | jobs | submit login

> And the destructor, if any, is called

Right, that's implied by a C++ object being deallocated. I understand how it works - it's just that it's really obvious if you know anything at all about how the stack works (and C++ destructors).




> it's just that it's really obvious if you know anything at all about how the stack works (and C++ destructors).

Which does not change it being an elegant solution to the problem of resource scoping does it?

Also the semantics of C++ destructor (and their relation to stack deallocation) had to be defined to get RAII, and it was, back in the very early 80s when the idea of resource scoping was not exactly well known.


It's using automatic storage duration and destructors tow age dynamically allocated memory (or some other resource which require manual management.). So yeah, that's it.


The "non obvious" part that makes it RAII is simply that the stack variable in question owns another resource besides itself. The stack variable is being used to wrap something else, be it a chunk of memory, a file handle, one or more other dynamically allocated objects, etc. The key in RAII is that when the stack variable wrapper goes out of scope, the wrapped resource (which is in addition to the stack variable) is deallocated, freed, released, etc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: