Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-04-03 14:03:21


----- Original Message -----
From: "Beman Dawes" <bdawes_at_[hidden]>

> >>
> >> |> ----- Original Message -----
> >> |> From: "Beman Dawes" <bdawes_at_[hidden]>
> >> |>
> >> |> > Although you have to be careful that the destructor is trivial,
it
> >> |> > is highly desirable to be able to use scoped_ptr with
> >> |> incomplete types.
> >> |>
> >> |> Why is that desirable?
> >>
> >> Support the pimpl idiom for forward declared types?
> >
> >// C.hpp
> >class Cimpl;
> >class C {
> >public:
> > ~C();
> >private:
> > boost::scoped_ptr<Cimpl> impl;
> >};
> >
> >// C.cpp
> >class Cimpl {
> >};
> >
> >C::~C()
> >{
> >}
> >
> >Am I missing something, or are you talking about a different idiom?
>
> That is the idiom I was talking about.

With the code as written, the definition of Cimpl is only needed in C.cpp,
which nicely shields the Pimpl's users from implementation details. Since
scoped_ptr<CImpl>::~scoped_ptr() is only instantiated in c.cpp, there
shouldn't be any problem with mentioning sizeof(T) (i.e. sizeof(Cimpl))
there.

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk