← Questions
Thread-safe reference-counted smart pointer in C++
0
I was asked this
No reports yet. Sign in to say where you were asked it.
Implement a reference-counted smart pointer class template in C++ from scratch, in the spirit of std::shared_ptr. Several owners can share one object; it is destroyed exactly once, when the last owner lets go.
Write the constructor, destructor, copy and move constructors and assignments, get, operator* and operator->, and use_count. Then make the count safe across threads with atomics, explain the memory ordering you need, and discuss self-assignment, exceptions and what a weak pointer would add.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
