Now if the program is killed before init() is complete, then exit() will be called and g_mod will not have been initialized which will be a not-so-clean end to the program.
Since MyClass is always dynamically allocated pointer, is this a completely insane solution?
If MyClass's dtor is running... it has already been deleted... so yes that is a terrible idea.
Furthermore there is no way (from that) to guarantee that MyClass was created on the heap and therefore SHOULD be deleted (ie: if you put it on the stack, you must not delete it!)
EDIT:
any reason you can't use RAII? You really should use it whenever you're doing dynamic allocation and/or manual resource management.
@Disch Ooo, didn't think of std::unique_ptr. Helpful as always, thanks.
@ne555 these are pointers so that I can control in what order the objects are created There are several instances of MyClass* each with their own explicit entry points and if I define these in the global scope without pointers, I can't control which order they get created.