[C++-sig] automatic downcasting with V2

Daniel Paull dlp at fractaltechnologies.com
Thu Dec 19 04:35:58 CET 2002


> >> Furthermore, C++ inheritance hierarchies in general form a DAG.  If
> >> the actual type of the object isn't registered, there may not be
any
> >> single most-derived type which is registered:
> >>
> >>        A
> >>       / \
> >>      B   C  <= B and C are registered
> >>       \ /
> >>        D    <= D is not.
> >>
> >>
> >> So, what about cases like this one?
> >
> > If you try to convert "D*" to python, you'd get a wrapped up "A*",
just
> > like before.
> 
> Hmm, no...
> 
> If you convert D* to python, you get a Python 'D' object.  You
> wouldn't be able to convert a D* to python unless D were registered.
> The question is, what happens when you convert an A* which points to a
> D object to python?

Sorry, I meant to state that if you pass a "D" object as an "A*" to
python, you should get an "A" object in python if D is not registered.
I think we all agree on this behaviour :)

> > Given this, I think that a sensible set of caveats on the use of
> > automatic downcasts can be formed.
> >
> > Looking back at the DAG and keeping with this philosophy, I think
you
> > have to take the approach that and instance of "D" returned as an
"A*"
> > must:
> >
> > 1) be converted to a wrapped "D*"
> > 2) if (1) fails (eg, D is not registered), either return a wrapped
"A*",
> > or,
> > 3) signal an error.
> >
> > This sort of scheme would be perfect for my needs.
> 
> OK, then.  It'll have to be #2 or we'll kill abstract factories, and
> nobody wants that ;-)

Sure, #2 will get me moving nicely.

I had imagined #3 being optional, say, by a different return value
policy or something similar.  In retrospect, it is hardly an issue for
boost.python as the result of the conversion can be asserted on the
python side if the behaviour of #3 is really needed...

I agree, only support #2.

Cheers,

Dan






More information about the Cplusplus-sig mailing list