Thursday, 11 February 2021

Chapter 19 // Exercise 10 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and a modified version of the std_lib_facilities header found here.

Chapter 19 // Exercise 10

Implement a simple unique_ptr supporting only a constructor, destructor, ->, *, and release(). In particular, don't try to implement an assignment or copy constructor.


I left the crtDetectMemoryLeaks function in this one and it works for new and delete as well! Happy days. Glad I did as my first run leaked memory. I had forgotten which way round to delete in the destructor. I used to see a lot of code that would do:
delete object;
object = nullptr;

I messed it up and of course that memory was lost because I didn't stop to think. I did google to find out if it's standard practice to delete and null and the consensus is; not really as it may cover up double delete bugs. We've had problems with double deletes at work so I don't want to contribute to covering up those as they are nasty to solve.

No comments:

Post a Comment