#include <iostream.h>
class overload {
public:
// Overloaded new
void* operator new (size_t sz)
{
cout <<"\nNew operator are used for allocated memory in Object Creation";
// Invoke the default new operator
return ::new overload();
}
// Overloaded delete
void operator delete(void* ptr)
{
cout <<"\nDelete operator are used for deallocated memory in Object Destroy";
// Invoke the default delete operator
::delete ptr;
}
};
void main()
{
overload* object = new overload();
delete object;
}
Output:
class overload {
public:
// Overloaded new
void* operator new (size_t sz)
{
cout <<"\nNew operator are used for allocated memory in Object Creation";
// Invoke the default new operator
return ::new overload();
}
// Overloaded delete
void operator delete(void* ptr)
{
cout <<"\nDelete operator are used for deallocated memory in Object Destroy";
// Invoke the default delete operator
::delete ptr;
}
};
void main()
{
overload* object = new overload();
delete object;
}
Output:
No comments:
Post a Comment