Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-02-11 16:21:08


"Powell, Gary" <powellg_at_[hidden]> writes:

> One other thing that makes writing base class and derived classes easier is to add this to the ref struct
>
> class X {
> ....
> private:
> struct ref {
> ref (X *rhs) : p (rhs) {}
>
> template<class T> // new
> ref (T *rhs) : p(rhs) {} // compiles if T is derived from X.
>
> X *p;
> };
>
> .....
> };
>
> Then in the derived class you can call:
>
> class Y : public X {
>
> ....
>
> Y(ref rhs)
> : X (rhs.p) // no cast needed to call X::ref
> , id(++cnt)
> , owner(true)
> {
> ....
> }
>
> ....
> };
>
>
> Anyway the more I play with this the better I like it.

If Rani is right about the reference binding I'd like to find some way
to library-ize this idiom, so your "ref" converting constructor will
come in handy. BTW, you don't need the other "ref" constructor
anymore.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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