Boost logo

Boost :

From: Vladimir.Batov_at_[hidden]
Date: 2007-11-01 16:12:05


>> Inherited Pimpls
>>
>> sdfsd
>>
>>
>> Polymorphic Implementations
>>
>> sdfs

>I'd very much like to see those sections, or even only how you'd go about

>re-using a pimpl_ptr from a base class, inheriting Derived::Impl from
>Base::Impl.?

It has to be remembered that Pimpl idiom is about implementation hiding,
i.e. it's about implementation and it's about hiding. It's not about
making a class to behave as a pointer -- that is done by shared_ptr and
done beautifully. A Pimpl-based class is by all means an ordinary class.
The fact that its implementation is done in pimpl fashion is an
implementation detail and is irrelevant when one inherits from that class.
Therefore, as far as inheriting from a Pimpl-based class is concerned,
there is not much to it. That is,

class Test : public pimpl<Test>::pointer_semantics
{
};

>From outside Test is an ordinary C++ class and NOT a pointer or anything
like, say, shared_ptr<Test>. So, to inherit from it

class Derived : public Test
{
};

Certainly it is unreasonable to expect all the perks that pimpl<> provided
while we built Test to percolate to Derived.

As far as "inheriting Derived::Impl from Base::Impl", then I've been doing

pimpl<Base>::implementation
{
};

pimpl<Derived>::implementation : pimpl<Base>::implementation
{
};

on one occasion. So far, my experience is that you cannot make much use of
it (like Test being polymorphic and housing Derived implementation
instead)... unless you are prepared to forgo implementation hiding --
something the Pimpl is deployed for in the first place. If you do not care
for implementation hiding, then I'd suggest going with shared_ptr instead.

Thanks,
Vladimir.


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