3 ms·
> scoped_ptr which worked just like the one at a certain company. It gives you a few neat things, like the ability to just forward-declare a class inside your .
by hellofunk 9y ago
> scoped_ptr which worked just like the one at a certain company. It gives you a few neat things, like the ability to just forward-declare a class inside your .h file and not include the whole thing right there.
But all pointers do this in C++? Why would you need a smart pointer to do this for you?
- ben0x539 9y agoI think the starting point is having a by-value member of that class, which has convenient automatic destruction semantics, but requires the actual class definition in scope. To lift that requirement, you move to a pointer field, and if you go with a scoped_ptr rather than a raw pointer, you don't lose the automatic destruction.
- hermitdev 9y agoscoped_ptr has the same issue due to the implicit destructor needing to know how to destroy the thing being held. The trick is you need to explicitly define your destructor (and it's implementation needs to have full knowledge of what it's pointing to). It doesn't have to do anything - ideally, it should be empty. This is known as the PIMPL idiom, or Cheshire Cat.
- ben0x539 8y agowow somehow i was sure i could get out of that just by having the destructor of the containing class in a separate compilation unit, that's unfortunate.