Boost logo

Boost :

From: Ronald Garcia (rgarcia4_at_[hidden])
Date: 2000-12-26 16:45:56


>>>>> "BK" == Bill Klein <bill_at_[hidden]> writes:

>> Can you declare a scoped_ptr without the parameter class
>> definition being visible? I have tried this before with
>> std::auto_ptr and gotten compiler errors because "delete
>> SocketImpl" couldn't be defined at compile time. I end up using
>> a plain pointer and handling new and delete by hand.

    BK> In order to get around this, I define a non-inline destructor
    BK> (even if it just has an empty body). This way the class is
    BK> defined where the destructor is and the compiler can do the
    BK> proper deletion etc...

Ahh...so in order to use the pimpl_ idiom, at least in this form, you
need to have a non-inline constructor (in order to call "new Impl")
and a non-inline destructor (so that the scoped_ptr is instantiated at
a scope where the Impl definition is visible). I would guess that all
of this is discussed in Exceptional C++, but of course my copy is far
away from me at the moment.

In this case, the tradeoff is less coupling between units (I'm under
the impression this is primarily used to improve compile times, but in
general the above is true) at the expense of no inline constructor or
destructor. In addition, implementation code is written in terms of
"pimpl->item" instead of plain "item" (small beans, since much code is
write-once read-many).

Anything else?

ron


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