I want to override delete operator in my class. Here\'s what I am trying to do,but not succeeding.
class Complex{
void *operator new(size_t
As the error message indicates, you can't delete
a void*
. Try this:
// See http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=40
#include // for size_t
class Complex
{
public:
Complex() {}
~Complex() {}
static void* operator new (size_t size) {
return new char[size];
}
static void operator delete (void *p) {
return delete[] static_cast(p);
}
};
int main () {
Complex *p = new Complex;
delete p;
}