return boost::shared_ptr<some internal>
I have a class that has a member something like this: class A { boost::shared_ptr<B> b; }; boost::shared_ptr<B> get_b (A const& ...) { return A.b; } where class B is already exposed to python in a different module. I tried to provide access to the internal member A.b: class_<A> ... .add_property ("b", &A::get_b) It seems that attempting to provide access to this internal member fails, with a message about no conversion from c++ type blah blah. The c++ type represented by this internal state is already exposed in a different python module, which has also been imported into python.
From what I can gather from ancient messages on the web, this usage just isn't going to work.
Any thoughts?
On Fri, 14 Jun 2013 12:57:48 +0100, Neal Becker <ndbecker2@gmail.com> wrote:
I have a class that has a member
something like this:
class A { boost::shared_ptr<B> b;
};
boost::shared_ptr<B> get_b (A const& ...) { return A.b; }
where class B is already exposed to python in a different module.
I think this depends on (at least) a few things:- 1. libboost_python shouldn't be linked statically into each extension. If it is, then the to_python converter registry will be duplicated in each extension, so one extension module wouldn't be able to locate to python converters (e.g. class_'s) registered in other extensions. 2. Class B will need to be exposed with a shared_ptr as its instance holder / object manager(?).. e.g. class_<B, shared_ptr<B> > ... 3. Like you've said, you'll also need to import B into Python, but as there's no inheritance involved between A and B (no 'bases<>' declared), I don't think the import order is completely relevant here, so long as both modules have inserted their to_python converters into a single registry. HTH, Alex
participants (2)
-
Alex Leach -
Neal Becker