Wednesday, May 11, 2016

Overload new and delete operators.


#include<iostream.h>
#include<conio.h>

class MyClass
{
public:
void* operator new (size_t sz)
{
cout << "Object Created" << endl;
        return ::new MyClass();
}
void operator delete(void* ptr)
{
cout << "Object Destroyed" << endl;
::delete ptr;
    }
};

void main()
{
MyClass* obj;
obj= new MyClass();
delete obj;
getch();
}

No comments:

Post a Comment