[C++-sig] C++ object pointers contained in a vector
roman.yakovenko at gmail.com
Wed Oct 18 22:28:17 CEST 2006
On 10/18/06, Noah Schwartz <noah.schwartz1 at gmail.com> wrote:
> On Wednesday 18 October 2006 16:09, Roman Yakovenko wrote:
> > On 10/18/06, Noah Schwartz <noah.schwartz1 at gmail.com> wrote:
> > > Hi,
> > >
> > > I've used the vector_indexing_suite to expose vectors containing pointers
> > > to some class. I see that I can't iterate over this vector in Python like
> > > I can with say, a vector of floats. I get the following error:
> > > TypeError: No to_python (by-value) converter found for C++ type: MyClass*
> > >
> > > MyClass is already exposed properly. I can even use a MyClass* fine in
> > > Python when other C++ functions return a pointer to one.
> > >
> > > I am guessing that I need to define a to_python converter either in
> > > MyClass or in a new class, MyClass*. Not really sure how that works
> > > though.
> > Try to set NoProxy to true
> > http://boost.org/libs/python/doc/v2/indexing.html#indexing_suite
> > Does it help?
> So, something like this?
> class_<std::vector<MyClass *> >("VectorMyClassP")
> .def(vector_indexing_suite<std::vector<MyClass *>, true >())
> Same problem...
:-(, for some reason I thought this would work:
Take a look on this post:
I am not sure about indexing suite v2, because you can change call policies:
You can find documentation for indexing suite v2 here:
C++ Python language binding
More information about the Cplusplus-sig