|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-03-02 13:35:41
Robert Ramey wrote:
> The follow little example illustrates an issue I have with
> scoped_ptr. I would like to use this to automatically manage
> destruction of a pointer to and undefined class. It seems that
> scope_ptr is instantiating its
> destructor "too early" and complaining about incomplete type for b;
>
> In my view, this should not occur as ~a() isn't defined yet.
>
> The following example fails on vc 7.1 and gcc 3.2
You also need to declare the default constructor.
> struct b;
>
> struct a
> {
> boost::scoped_ptr<b> pimpl;
a();
> ~a();
> };
>
> int main()
> {
> a a_instance;
> }
Why, you might ask. At least I did.
The implicitly generated default constructor:
a(): pimpl()
{
}
constructs pimpl and needs to instantiate ~scoped_ptr because if the body of
the constructor throws, it'll need to destroy pimpl.
It's pretty obvious that in our case the empty body cannot throw, but the
compilers are probably right to require a definition for ~scoped_ptr.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk