Question: Shared and weak pointers are one way to solve memory leaks. When a shared pointer points at something, it adds one to a refcount. When
Shared and weak pointers are one way to solve memory leaks. When a shared pointer points at something, it adds one to a refcount. When the pointer stops pointing at it, the refcount goes back down. When the refcount hits zero, the object gets deleted because nobody is holding on anymore. A weak pointer can also point at the same object, but it doesn't add to the refcount. When the object gets deleted by the final shared pointer letting go, all weak pointers are cleared to null.
a) What do you think the class definitions for SharedPtr and WeakPtr look like? Make sure to explain how the properties and methods you list make the system work.
Step by Step Solution
3.54 Rating (157 Votes )
There are 3 Steps involved in it
Here is the solution a The class definitions for SharedPtr and WeakPtr might look something like this cpp A class that represents a shared pointer template class SharedPtr private A pointer to the obj... View full answer
Get step-by-step solutions from verified subject matter experts
