|
-
January 15th, 2010, 02:45 AM
#1
Delete Operator overloading with multiple arguments.
Hi,
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
#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'
}
Output
Hello
I want to call the delete with size operator. So please help me how can this program will give the output as World.
Thanks in advance for my help.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|