N
Nephi Immortal
I implement operator new and operator delete by adding an extra parameter. If I want to implement one heap class and create more than one heap object, then both operator new and operator delete are able to select correctheap object. How can I do that?
I do not want to create operator new and operator delete inside class body. It is independent to work with all types.
class Heap
{
public:
Heap() {}
void run() {}
};
void* operator new(
size_t size,
Heap& heap
)
{
heap.run();
return 0;
}
void operator delete(
void* p,
Heap& heap
)
{
heap.run();
}
int main()
{
Heap heap;
char* byte = new( heap ) char;
delete( heap ) byte; // ? does not compile -- how?
return 0;
}
I do not want to create operator new and operator delete inside class body. It is independent to work with all types.
class Heap
{
public:
Heap() {}
void run() {}
};
void* operator new(
size_t size,
Heap& heap
)
{
heap.run();
return 0;
}
void operator delete(
void* p,
Heap& heap
)
{
heap.run();
}
int main()
{
Heap heap;
char* byte = new( heap ) char;
delete( heap ) byte; // ? does not compile -- how?
return 0;
}