Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ helps sample the outputj should be : new 0 created new 1 created new 2 creat

ID: 3816813 • Letter: C

Question

C++ helps

sample

the outputj should be :

new
0 created
new
1 created
new
2 created
new
3 created
new
4 created
0
1
2
3
4
0 destroyed
delete
1 destroyed
delete
2 destroyed
delete
3 destroyed
delete
4 destroyed
delete

Instructions Add to your Counter class overloaded operators new and delete that each will print"new" and "delete" respectivelly and then will allocate and delete memory using your own implementation, which may use malloc/free or the gobal new/delete operators. Your code will be tested with the overloadedNewDelete.cpp file.

Explanation / Answer

//new and delete methods, add below methods to Counter.cpp file and declaration of these functions to Counter.h file

void *Counter::operator new(size_t s)
{
   Counter *cnt;
   cnt = ::new Counter;
   cnt->ID = new int[s];
   return cnt;
}

void Counter::operator delete(void *s)
{
   Counter *cnt;
   cnt = (Counter*)s;
   delete (int*)cnt->ID;
   ::delete s;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote