4 ms·
I'm pretty sure making a copy of a shared_ptr needs to modify it, so having a const reference doesn't work.
by mark-r 7y ago
I'm pretty sure making a copy of a shared_ptr needs to modify it, so having a const reference doesn't work.
- tlb 7y agoIt doesn't modify anything inside the shared_ptr itself, but a refcount which is pointed to by a pointer field in the shared_ptr. So you can say foo(shared_ptr<T> const &x) { saved_x = x; } and it'll update the refcount exactly once when doing the assignment.
- mark-r 7y agoThat's the problem with modern C++, you can't reason about it on general principles - you have to know way too much about implementation detail.