title: Trying to pass a struct member function to atexit
body: <p>I am writing a debugger in C++ and upon exit I need it to cleanup any breakpoints set in the debuggee. </p>
  
  <p>I have made a <code>struct</code> called <code>BREAKPOINT_INFO</code> that contains the information needed to cleanup each breakpoint. Information such as a handle to the process(<code>hProcess</code>), the virtual memory address of the breakpoint(<code>lpBreakPoint</code>), and the opcode of the original instruction that was replaced(<code>instr</code>).</p>
  
  <p>I then have a <code>CleanUp</code> member function that uses the data members described above to restore the original instruction so the debuggee doesn't crash.</p>
  
  <pre><code>typedef struct
  {
      HANDLE hProcess;
  
      PCHAR  lpBreakPoint;
  
      CHAR   instr;
  
      void CleanUp()
      {
          DWORD dwError = 0;
          std::ostringstream oss;
          LPSTR szErrorRest = (LPSTR)"Error restoring original instruction: ";
  
          if(!WriteProcessMemory(hProcess, lpBreakPoint, &amp;instr, sizeof(CHAR), NULL))
          {
              dwError = GetLastError();
  
              oss &lt;&lt; szErrorRest &lt;&lt; dwError;
  
              szErrorRest = oss.str().c_str();
  
              MessageBox(NULL, szErrorRest, "ERROR", MB_OK|MB_ICONERROR);
          }
      }
  }BREAKPOINT_INFO, *PBREAKPOINT_INFO;
  </code></pre>
  
  <p>However, when I try to pass my member function for each <code>BREAKPOINT_INFO</code> structure, I get a compilation error:</p>
  
  <p><code>C:\...\...\main.cpp|39|error: cannot convert 'BREAKPOINT_INFO::CleanUp' from type 'void (BREAKPOINT_INFO::)()' to type 'void (__attribute__((__cdecl__)) *)()'|</code></p>
  
  <p>And even after trying to cast to that type it fails to compile. Is it possible to pass a member function to <code>atexit</code>? And if so, how would I go about doing so? Thank you for your time.</p>