From: William Kempf (sirwillard_at_[hidden])
Date: 2001-01-03 11:26:23


--- In boost_at_[hidden], Bill Klein <bill_at_o...> wrote:
>
> >> It depends what you mean by "overkill", I guess. The suggestions
eliminate
> >> casting, some exception-safety issues, and probably the need to
write a
> >> destructor in your class. Sounds like simplification to me.
What's the
> >> downside?
>
> Bill Kempf wrote...
> >For the "Pimpl Idiom" I prefer to use code like this:
> >
> >class my_class
> >{
> > ...
> >private:
> > class impl; // scope it in the class to prevent name clashes
> > impl* pimpl;
> >};
> >
> >This requires code in my_class to manage the lifetime of the impl
> >instance, but this is trivial and impacts only the implementation
of
> >my_class, while making visibility of the destructor a non-issue...
>
> Err... it forces you to write a non-inline destructor for my_class
> to delete pimpl... In what way is this better than having scoped_ptr
> force you to write a non-inline destructor which may be empty (if
> you don't have anything to do there)?

It's not better, just more obvious. Many coders (as evidenced by
these threads) are confused about how to make scoped_ptr<> work in
cases like this. It's not obvious that a non-inlined destructor is
required.

The big draw back is in the compile time dependencies, though.

Bill Kempf