[C++-sig] (Nat Goodspeed) pass function pointerto c
Stefan Seefeld
seefeld at sympatico.ca
Mon Oct 9 02:32:53 CEST 2006
Qinfeng(Javen) Shi wrote:
> Hi Nat,
>
> Thank you very much.
> I tried what you said, but it seems boost::python::object can't be
> converted to float by (float) (op(a,b)). So I converted the pointer of
> op's result into float*, but got a unexpected result. Something wrong
> with my code?
>
> -------------------------c extension---------------
> boost::python::object op;
>
> void process(arg1,..., boost::python::object arg_op){
> ...
> op = arg_op;
> ...
> float a = 1;
> float b = 2;
>
> boost::python::object rlt = op(a,b);
> float * f = (float *) (rlt.ptr());
make that
float f = boost::python::extract<float>(rlt);
Would that work ?
On a stylistic note:
There is almost never a reason to use C-style casts
in a C++ program. At least use one of const_cast, static_cast,
or reinterpret_cast instead.
HTH,
Stefan
--
...ich hab' noch einen Koffer in Berlin...
More information about the Cplusplus-sig
mailing list