3 ms·
I think the starting point is having a by-value member of that class, which has convenient automatic destruction semantics, but requires the actual class defini
by ben0x539 9y ago
I 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 9y 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.