[C++-sig] (Stefan Seefeld) pass function pointerto c

Stefan Seefeld seefeld at sympatico.ca
Wed Oct 18 02:20:43 CEST 2006


Qinfeng(Javen) Shi wrote:
> Hi Stefan,
> 
>> Python has no notion of pointer. So, the float * is accepted, but
>> that's because for convenience the boost.python side accepts it as a
>> pointer to a single item. You can't pass arrays like that.
>> (You may want to look at
>> http://boost.org/libs/python/doc/v2/indexing.html
>> to see how you can export containers.)
> 
> I saw this indexing method. I want to expose float* to python, so that
> boost::python::object(float*,float*) is callable in c extension.
> 
> But here float* is not a class. If even I "typedef float* vector;", then
> expose vector as following,
> class_<vector>("Vec")
>        .def(vector_indexing_suite<vector>())
>    ;
> 
> it will report a error."error: `float*' is not a class, struct, or union
> type"

Right. Typedefs don't create new types, only aliases, and so the above fails.

> Could you tell me how to expose it?

I'd wrap the array pointed to by your float pointer into an actual class.
That has the side-effect of allowing you to make element-access a little
safer, and to allow introspection (report the array's size, for example).
Then you can expose that class using the index_suite I pointed you at
in the other mail.

Regards,
		Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list