Here we have five code snippets that will benefit from using smart pointers. By replacing every explicit new with make_unique or make_shared, (alternatively by explicitly instantiating smart pointers) we will fix memory leaks, segmentation faults, and make most cleanup code unnecessary.
- Do you know which kind of pointer is used for what?
- Raw pointer
std::unique_ptrstd::shared_ptr
- C++-14 for
std::make_unique/std::make_shared. Understand what these functions do. - Helpful: Move semantics for
problem2(), but one can do without.
- In the essentials course, work on
problem1andproblem2, and fix the leaks using smart pointers. - In the advanced course, work on
problem1toproblem5. Skipproblem4andproblem5if you don't have enough time. - Dedicated instructions are given in each cpp file.
- Each one is written so that you easily check if the problem is solved or not.
- If seen in course before, you are also advised to try external tools such as valgrind:
valgrind --leak-check=full --track-origins=yes ./problem1