I have an requirement to overload the delete operator in C++, but it should also accept the sizeof() the object that is to be deleted. Actually I am trying to built a custom memory allocator and deallocator like a pool, which makes me to overload the delete operator.
Small example of the problem is
Output
I want to call the delete with size operator. So please help me how can this program will give the output as World.
Small example of the problem is
Code:
#include <new>
#include <iostream>
using namespace std;
void operator delete(void* p)
{
cout << "Hello" << endl;
free(p);
} // (1)
void operator delete(void* p, size_t s)
{
cout << "World" << endl;
free(p);
} // (2)
int main()
{
int* p = new int;
delete p; // This cannot render to show 'Hello' or 'World'
}
Hello
Comment