We have already defined a class Device with:
Device
void status() { cout << "Device is active\n"; }
Your task is to:
shared_ptr<Device>
main()
weak_ptr<Device>
The program will already handle converting the weak_ptr into a shared_ptr with .lock() and calling status().
weak_ptr
shared_ptr
.lock()
status()
Example
Output:
Device is active
Why this output?
Because the weak_ptr observes the object managed by shared_ptr, and the program locks it to safely call status().
Question Significance
This shows how weak_ptr is linked to a shared_ptr, but does not extend the lifetime of the object.
Test Cases
Test Results
Input
Expected Output