#include#include static unsigned int totalCount = 0; struct TestStruct { public: TestStruct() { } ~TestStruct() { } }; void* operator new(size_t size) { printf("(Enter new)n"); ++totalCount; char* alloced = nullptr; try { alloced = (char*)malloc(size); } catch(std::bad_alloc exception) { throw(exception); } return alloced; } void operator delete(void* pointer) { printf("(Enter delete)n"); --totalCount; try { free(pointer); } catch(std::exception s) { throw(s); } } int main(int argc, const char** argv) { printf("This is a sample for rewirte operator new and deleten"); TestStruct* sss = new TestStruct(); delete sss; if (totalCount != 0) { printf("Trigger Assertion!n"); assert(totalCount == 0); } printf("Exit Normaly!n"); return 0; }



