sobrecarregar novo e excluir em c ++

Olá a todos,

Eu estava tentando sobrecarregar o novo e excluir para corrigir um problema de vazamento de memória no meu projeto. Mas ficou preso com algum erro de compilação.

Atualmente, esse código é um pouco gasto

Aqui está o meu arquivo hdr

#include <cstddef>
#include <iostream>
#include <list>
#include <stdarg.h>
#include <stdio.h>
using namespace std;
typedef unsigned int  DWORD;
void AddTrack(DWORD addr,  DWORD asize,  const char *fname, DWORD lnum);
char *OutputDebugString (const char *fmt, ...);
void RemoveTrack(DWORD addr);
void DumpUnfreed();

#ifdef _DEBUG
#define DEBUG_NEW new(__FILE__, __LINE__)
#define new DEBUG_NEW


   void *  operator new (unsigned int size, const char *file, int line)
  {
          void *ptr = (void *)malloc(size);
          AddTrack((DWORD)ptr, size, file, line);
          return(ptr);
  }
  /*inline void * operator new(unsigned int size)
  {
          void *ptr = (void *)malloc(size);
          AddTrack((DWORD)ptr, size, _FILE_,_LINE_);
          return(ptr);
  }*/
  void  operator delete(void *p)
  {
          RemoveTrack((DWORD)p);
          free(p);
  }

#endif


char *OutputDebugString (const char *fmt, ...)
{

char *p = NULL;
 size_t size = 1024;
 int n = 0;
 va_list ap;

 if((p = (char*) malloc(size)) == NULL)
 return NULL;

 while(1) {
  va_start(ap, fmt);
  n = vsnprintf(p, size, fmt, ap);
  va_end(ap);

 if(n > -1 && n < size)
return p;

/* failed: have to try again, alloc more mem. */
if(n > -1)      /* glibc 2.1 */
size = n + 1;
else            /* glibc 2.0 */
size *= 2;     /* twice the old size */

if((p = (char *)realloc (p, size)) == NULL)
return NULL;
}
}

typedef struct information {
DWORD   address;
DWORD   size;
char    file[64];
DWORD   line;
} ALLOC_INFO;

typedef list < ALLOC_INFO* > AllocList;
AllocList *allocList;




  void AddTrack(DWORD addr,  DWORD asize,  const char *fname, DWORD lnum)
  {
          ALLOC_INFO *info;

          if(!allocList) {
          //allocList = new AllocList;
            allocList = (AllocList*)malloc (sizeof (AllocList));
          }

          //info = new(ALLOC_INFO);
          info = (ALLOC_INFO*) malloc (sizeof (ALLOC_INFO));
          info->address = addr;
          strncpy(info->file, fname, 63);
          info->line = lnum;
          info->size = asize;
          allocList->insert(allocList->begin(), info);
  }

  void RemoveTrack(DWORD addr)
  {
          AllocList::iterator i;

          if(!allocList)
          if(!allocList)
                  return;
          for(i = allocList->begin(); i != allocList->end(); i++)
          {
                  if((*i)->address == addr)
                  {
                          allocList->remove((*i));
                          break;
                  }
          }
  }





void DumpUnfreed()
  {
          AllocList::iterator i;
          DWORD totalSize = 0;
          char buf[1024];

          if(!allocList)
                  return;

          for(i = allocList->begin(); i != allocList->end(); i++) {
                  sprintf(buf, "%-50s:\t\tLINE %d,\t\tADDRESS %d\t%d unfreed\n",
                          (*i)->file, (*i)->line, (*i)->address, (*i)->size);
                  OutputDebugString("%s",buf);
                  totalSize += (*i)->size;
          }
          sprintf(buf, "-----------------------------------------------------------\n");
          OutputDebugString("%s",buf);
          sprintf(buf, "Total Unfreed: %d bytes\n", totalSize);
          OutputDebugString("%s",buf);
  }

E meu main.cpp é

#include "mynew.h"
int main()
{

char *ptr = new char;
DumpUnfreed();

return 0;
}

Quando tento compilar, recebo o seguinte erro

[root@dhcppc0 new]# !g
g++ main.cpp -D_DEBUG
mynew.h:25: error: declaration of ‘operator new’ as non-function
main.cpp: In function ‘int main()’:
main.cpp:9: error: no matching function for call to ‘operator new(unsigned int, const     char [9], int)’
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/new:84: note:   candidates are: void* operator new(size_t)
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/new:88: note:                     void* operator new(size_t, const std::nothrow_t&)
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/new:94: note:                    void* operator new(size_t, void*)

Sei que há algo errado com meus #defines, mas não tenho certeza do que está errado.

Alguém por favor pode me tirar dessa

questionAnswers(2)

yourAnswerToTheQuestion