trainings/AdvancedCppV2/Presentation/smart_pointers_summary.md

957 B

Smart pointers - summary

  • #include <memory>
  • std::unique_ptr<> for exclusive ownership
  • std::shared_ptr<> for shared ownership
  • std::weak_ptr<> for observation and breaking cycles

Exercise: ResourceFactory

  1. Compile and run ResourceFactory application
  2. Put comments in places where you can spot some problems
  3. How to remove elements from the collection (vector<Resource*> resources)?
  4. Check memory leaks
  5. Fix problems