From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-11-08 14:27:10
----- Original Message -----
> I'm looking for a conversion from my own type to Python. I created a
> class called "Instance". I need to return that type back to Python.
> It is wrapped with boost as a class. The line I use (it isn't
> working) is:
> PyObject* GetInstance(MyList& l)
> Instance i;
> l.GetInstance(i); // pass by ref, not my code that does this
> return boost::python::to_python(i);
> I do have Instance wrapped and included into the module, but I can not
> return it back like this. The compiler says that Instance is not one
> of the converted types. I can return the "super" type (Instance is
> derived from InstBase), and that works, but it does not have the
> specific info I need from Instance. Does this clear things up more?
> Thank you very much for helping me out.
Hmm, I am guessing that the class_builder<Instance> is not declared yet at
the point you're trying to wrap the GetInstance function.
Keep in mind, though, that Boost.Python will try to /copy/ your Instance
object when you return it this way. As of today, the only way to return an
object by reference is to resort to "dangerous" trick as described at
http://www.boost.org/libs/python/doc/pointers.html under the heading "If you
can't (afford to) copy the referent, or the pointer is non-const"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk