Boost logo

Boost :

From: Rainer Deyke (root_at_[hidden])
Date: 2001-03-26 16:19:10


----- Original Message -----
From: "David Abrahams" <abrahams_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, March 25, 2001 9:47 PM
Subject: Re: [boost] Python: is there any way to make this work?
> > What I expected was for 'boost::python::to_python' to automatically
> perform
> > this conversion, minus the unsafe copy-instead-of-reference hack.
(There
> > really should be a way to downcast smart pointers.) The Boost Python
> > Library already knows about my class hierarchy and is already willing to
> > downcast, so why does it not perform this conversion?
>
> Ooooh! I think I might understand what you want now. Have you carefully
read
> http://www.boost.org/libs/python/doc/inheritance.html? I believe it
> addresses your needs directly.

I did read this. It say that objects of class Derived may be passed where
objects of class Derived are expected but type information has been lost.
However, this only applies when passing the object as an argument, not when
calling a method on the object:

struct A { virtual ~A(); }
struct B : A { void f(); }
void call_f(B& b) { b.f(); }
boost::shared_ptr<A> get_B() { return boost::shared_ptr<A>(new B); }

// Wrapper code ommited for brevity.
// Then in Python...
b = get_B()
call_f(b) # This works.
b.f() # This doesn't.

This strikes me as inconsistent. I suspect that it would be possible to
remove this inconsistency by modifying 'boost::python::to_python'.

--
Rainer Deyke (root_at_[hidden])
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

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