The idea of using the automatic object deconstruction of Stack allocated objects got me thinking of using the system as a way to initialize and clean up 3rd party libraries.
Example:
#include <libA.h>
#include <libB.h>
namespace library {
class Wrapper {
Wrapper() {
libA_init();
libB_init();
}
~Wrapper() {
libB_exit();
libA_exit();
}
}
}
int main() {
library::Wrapper library;
}
People already argued on SO if the simple use of automatic stack deallocation should be called RAII as RAII withouth the R is simply the way OO works. (Allocation is initialization? Sounds like calling a constructor to me.)
Is this usage a well known antipattern or a good idea to organise code?