C/C++ does have a function called atexit() that does that.
A sample code fragment to use the same is as follows.
#include <cstdlib>
#include <iostream>
using namespace std;
void do1()
{
std::cout << "do1 implementation\n";
}
void do2()
{
std::cout << "do2 implementation\n";
}
int main()
{
atexit(do1);
atexit(do2);
exit(EXIT_SUCCESS);
}
Sample output:
$ g++ -Wall -Werror testexit.cpp
[noname@localhost test]$ ./a.out
do2 implementation
do1 implementation
No comments:
Post a Comment