Class specific new/delete
Is it possible to overload class specific new/delete that is called when arrays of objects are created.
class Foo;
Foo* f = new Foo[10]; // calls overloaded new
delete[] f; // calls overloaded delete
Thank you.
Yes, it is possible. There is a tutorial about overloading new
and delete
here, and there is a nice example of overloading new
and delete
for array, here.
class Myclass
{
public:
void* operator new(size_t);
void operator delete(void*);
void* operator new[](size_t);
void operator delete[](void*);
};
链接地址: http://www.djcxy.com/p/73034.html
上一篇: 分配的内存和数组
下一篇: 特定于类的新/删除