Question: 6. (Weak Pointers) A weak pointer is an observer of a shared pointer. It is useful as a way to avoid dangling pointers and also
6. (Weak Pointers)
A weak pointer is an observer of a shared pointer. It is useful as a way to avoid dangling pointers and also when we wish to use shared resources without assuming ownership.
Answer the following questions:
a) Create a shared pointer, print its use count and then create a weak pointer that observes it. Print the use count again. What are the values?
b) Assign a weak pointer to a shared pointer and check that the weak pointer is not empty.
c) Assign a weak pointer to another weak pointer; assign a weak pointer to a shared pointer. What is the use count in both cases?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
