0
void operator delete(void *p)
{
    printf("\nDELETE");

    // code to actually delete/free object
}


int _tmain(int argc, _TCHAR* argv[])
{

    int *p = new int(10);

    delete p;

    getchar();
    return 0;
}

I am getting error operator delete already defined

I want to override new and delete operator globally.

Vijay
  • 2,021
  • 4
  • 24
  • 33

2 Answers2

0

Did you only implement it or also declare it? Afaik, you only need to implement it.

Nils Werner
  • 34,832
  • 7
  • 76
  • 98
0

The deallocation function can be replaced/overloaded in two ways:

in the global scope: in order to call it, the signature of the overloaded allocation functions must be visible at the place of deallocation, except for implicitly declared default deallocation functions. This allocation function will be used for all deallocations with corresponding parameters in the current program in the local scope: the overloaded operator delete must be static public member function of the class. This deallocation function will be used only for deallocations of that particular class.

uniqrish
  • 1,750
  • 1
  • 11
  • 7