a. place the call to the exit handler member function in the destructor of a class.
b. create an instance of the class with a static storage duration.
the order of calling C atexit / C++ destructors for objects with a static storage duration is specified by secion 3.6.3/3 of the standard:
If a function is registered with atexit then following the call to exit, any objects with static storage duration initialized prior to the registration of that function shall not be destroyed until the registered function is called from the termination process and has completed.
For an object with static storage duration constructed after a function is registered with atexit, then following the call to to exit, the registered function is not called until the execution of the object's destructor has completed.
If atexit is called during the construction of an object, the complete object to which it belongs shall be destroyed before the registered function is called.