Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-03-25 18:28:15

Hi Rainer,

I don't think I can help you make it work "as expected", since I'm not
certain what you expect. I can see many problems with the code you posted
that would prevent it from working.
1. you need to use boost::shared_ptr or some other smart pointer that
actually exists (e.g. std::auto_ptr)
2. you can't rely on implicit conversion from B in make_A() since both of
the smart pointers I mentioned have explicit constructors
3. class A needs a virtual destructor, since you will be destroying a B
through the A pointer.
4. class A needs to declare f as a (possibly pure) virtual function. This
isn't Python; in C++, run-time polymorphism requires a declaration of
polymorphic functions in base classes!

It looks to me like you need some background in object-oriented C++
programming. I don't think I can explain it all, at least not well. There
are any number of good books out there...

Hope this helps,

P.S. For the code you posted, exposing class B and B::f is probably

----- Original Message -----
From: "Rainer Deyke" <root_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, March 25, 2001 2:27 PM
Subject: [boost] Python: is there any way to make this work?

> Is there any way to make the following work as expected:
> class A {}
> class B : public A { public: void f(); }
> boost::smart_ptr<A> make_A() { return new B(); }
> void init_module()
> {
> boost::python::module_builder module("module");
> boost::python::class_builder<A> A_class(module, "A");
> boost::python::class_builder<B> B_class(module, "B");
> B_class.declare_base(A_class);
> B_class.def(B::f, "f");
> module.def(make_A, "make_A");
> }
> // Then in Python...
> x = make_A()
> x.f()
> --
> Rainer Deyke (root_at_[hidden])
> Shareware computer games -
> "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
> To unsubscribe, send email to: <mailto:boost-unsubscribe_at_[hidden]>
> Your use of Yahoo! Groups is subject to

Boost list run by bdawes at, gregod at, cpdaniel at, john at