3 ms·
I've used this in the past, but I've had trouble with "phantom callbacks". Where the logic of the program assumes the object is gone, and it ends up changing p
by jdsully 8y ago
I've used this in the past, but I've had trouble with "phantom callbacks". Where the logic of the program assumes the object is gone, and it ends up changing program state unexpectedly. The problem with shared pointers is ownership is not clear - just because you don't segfault doesn't mean there's no bug.
- zelos 8y agoExactly. I've had endless arguments about that exact point with shared_ptr. IMHO, shared_ptr should be used as a last resort, where ownership of something truly is shared. Use unique_ptr for everything else. Just using it for convenience for things like callbacks will lead to weird, hard-to-debug bugs in more complex code.