PPT:





Code:

#ifndef OBJECT_H#define OBJECT_Hnamespace DJLib{class object{public: void* operator new (unsigned int size) throw(); void operator delete (void* p); void* operator new[](unsigned int size) throw(); void operator delete[](void* p); bool operator == (const object& obj); bool operator != (const object& obj); virtual ~object()= 0;};}#endif // OBJECT_H

#include "object.h"#include <cstdlib>#include <iostream>using namespace std;namespace DJLib{void* object::operator new (unsigned int size) throw(){ return malloc(size);}void object::operator delete (void* p){ free(p);}void* object::operator new[](unsigned int size) throw(){ return malloc(size);}void object::operator delete[](void* p){ free(p);}bool object::operator == (const object& obj){ return (this == &obj);}bool object::operator != (const object& obj){ return (this != &obj);}object::~object(){}}

#include <iostream> #include "object.h"using namespace std;using namespace DJLib;class Test: public object{public: int i; int j;};class Child : public Test{public: int k;};int main(){ object* obj1 = new Test(); object* obj2 = new Child(); delete obj1; delete obj2; return 0;}