[C++-sig] Wrapping pointers

Tony Kirke tkirke at gmail.com
Thu Apr 13 22:16:18 CEST 2006


Did you get an answer to this?
I am trying to figure out the same thing except my pointer is to an object
of a different class instead of  the same class

On 4/5/06, Dominic Sacré <dominic.sacre at gmx.de> wrote:
>
> Hi,
>
> I'm having trouble exporting C++ pointers to Python. My code looks like
> this:
>
> class A
> {
>     A *p;
>     ...
> };
>
> BOOST_PYTHON_MODULE(test)
> {
>     class_<A>("A", init<>())
>         .def_readonly("p", &A::p)
>         ...
>     ;
> }
>
> Now every time I try to access A::p from Python I get this error:
>
> TypeError: No to_python (by-value) converter found for C++ type: A*
>
> I searched the list archives and found a message about the same issue,
> where the only suggestion was to use
>
> .def_readonly("p", make_getter(&A::p, return_internal_reference<1>()))
>
> instead, but this doesn't help either. On the contrary, this causes a
> segfault every time I use A::p (although p points to a valid object, at
> least in C++).
> So what should I do to access this pointer from Python?
>
> Thanks,
>     Dominic
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060413/4be851e0/attachment.htm>


More information about the Cplusplus-sig mailing list