+ 1
How to make delete work with overloaded new
Hi I have overloaded operator new to observe the number of bytes allocated on heap. Now this throws warning when delete is called.how to get rid off this ? How to typecast void* returned from overloaded new to proper class type https://sololearn.com/compiler-playground/cv6Wr5pDH8ar/?ref=app Also how to make operator overloaded for new and new[] differently.
1 Antwort
0
Using operator ::new(t) in your overloaded operator new causes infinite recursion because it calls itself
The literal '1' is a character with an ASCII value of 49 so new Test['1'] allocates 49 objects
sizeof(ptr1) returns the size of the pointer not the size of the object; use sizeof(Test) for that
Hope this will help
Memory allocated with new[] must be deallocated with delete[] not delete