overloading new and delete in c++

前端 未结 2 1771
北海茫月
北海茫月 2021-01-14 20:49

HI All,

I was trying to overload new and delete to fix a memory leak problem in my project. But got stuck with some compilation error.

Currently this code is

相关标签:
2条回答
  • You've defined your new macro before your functions. Your code ends up looking like:

    void *
      operator new(__FILE__, __LINE__)(unsigned int size, const char *file, int line)
    

    Which is obviously wrong. Your should move the macro definitions underneath the functions (or better is to keep those functions in a .cpp file you link with.) For what it's worth, new is a keyword and cannot be an identifier, so your program is, strictly speaking, ill-formed.

    I recently posted my global memory operators framework. It might help you a bit.

    0 讨论(0)
  • 2021-01-14 21:14

    the signature don't match it sould be void* operator new (size_t size).

    overriding single object new signature is static void * operator new(site_t size),

    roni

    0 讨论(0)
提交回复
热议问题