overloading new and delete in c++

前端 未结 2 1885
北海茫月
北海茫月 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条回答
  •  不要未来只要你来
    2021-01-14 21:01

    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.

提交回复
热议问题