title: How to destruct instance in atexit()
body: <p>I want to <strong>call destructor</strong> of an instance (<em>proc</em>) always <strong>before my program ends</strong>, especially after <em>return 1</em> or <em>exit()</em> in <em>main</em>.</p>
  
  <p>I found C++ function <strong>atexit()</strong>, but it requires pointer to void function with no argument, so the code below cannot be compiled. <em>How I can solve it, please?</em></p>
  
  <p>Destructor of my instance requires MySQL connection.</p>
  
  <pre><code>#include &lt;WinSock.h&gt;
  #include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  #include &lt;stdio.h&gt;
  #include &lt;mysql.h&gt;
  #include &lt;string&gt;
  
  // Declarations for Mysql DB
  
  using namespace std;
  
  class Process {
    public:
       ~Process();
  };
  
  Process::~Process ()
  {
      // Interaction with DB
  }
  
  int main(void) 
  {
    // Join to DB
  
    atexit(proc.~Process); // Call desctructor of instance proc before program ends
  
    Process proc;
  
    // App code
  
    return 0;
  }
  </code></pre>