Round two of the same interview. The CTO finishes his third espresso: 'Okay, unique_ptr was the warm-up. Now shared_ptr — with a working reference count.' HR writes 'shared pointer = candidate strength' in her notebook. Don't let her down.
Implement a minimal SharedPtr<T> with reference counting. Copies share ownership; the managed object is deleted only when the last SharedPtr goes away.
use_count() returns the current number of ownersoperator= do before overwriting its current state?Store both the object pointer and a heap-allocated size_t* count.
Copy increments *count; destructor decrements it and frees both when it hits zero.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.