[C++-sig] c++ to python object conversion problem

Roman Yakovenko roman.yakovenko at gmail.com
Sun Mar 4 15:21:29 CET 2007


On 3/4/07, Tim Blechmann <tim at klingt.org> wrote:
> hi roman ... thanks for your hint
>
> i've added the wrapper code below the classes:
>
> > > class simple: boost::noncopyable{};
>
> class_<simple, boost::noncopyable>("simple");
>
> > > an instance of this class (or a derived one) is allocated from python
> > > and a pointer is stored in a class with a virtual function:
> > >
> > > class callback: boost::noncopyable
> > > {
> > >    virtual void overloadme(simple const &) = 0
> > >    void run(void) { this->overloadme(s_); }
> > >    void set(simple * s) {s_ = s;}
> > >    simple * s_;
> > > };
> > >
> > > this callback class is wrapped like it's described in the tutorial:
> > >
> > > class cbwrapper: callback, wrapper<callback>
> > > {
> > >    virtual void overloadme(simple const & s) {
> > >        this->get_override("overloadme")(s);
>
> class_<cbwrapper, boost::noncopyable>("callback")
>     .def("set",  &cbwrapper::set)

A problem could also be here, you have to set call policies:
http://boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies

Also, creating small and **complete** is much better way to get help.

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list