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
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;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.