Subj : Re: Can you mimic atexit() for class functions? To : borland.public.cpp.borlandcpp From : "Ed Mulroy [TeamB]" Date : Wed Oct 08 2003 12:08 am Classes are gone by the time atexit does its thing. An AddCallback function shouldn't be too difficult to write, but what you describe sounds as if it is supposed to be called at the end of the program. The way to do that with classes is to place either the code for what you want or the code for the call in the class destructor. If it needs to run at the end of the program, then write a class and declare a global instance of it and put the code in the destructor. .. Ed > gary wrote in message > news:3F837C67.3040604@cordelli.net... > > just wondering if it is possible to have a member function in various > (different) classes, but provide a single additional class that defines > some kind of "AddCallback()" function that each object of the various > other classes can call in order to add their own member function to a > callback list so that the single additional class can invoke the list of > added callbacks each in turn ? > > this is sort of like the way atexit() works in C, but in that case it is > easy to just define every added callback as "void (*pfn)()", whereas in > the C++ case, all the different classes would seem to necessarily have a > different declaration that can't be cast to "void (*pfn)()" to way you > can in C. > > any idea if this is possible at all, or am i just looking at it from the > wrong direction (i.e., writing C++ while thinking C) ? for instance, > would it be possible to do this if each of the different classes each > inherited a member function from the single additional class so that > each different class' callback function had the same type (e.g., "void > (CallbackList::*MyCallback)()", if i did that right) ? > > hope this question is clear. it confused even me, and i asked it... .