[C++-sig] IndexError when returning pointer

David Abrahams dave at boost-consulting.com
Wed Apr 16 02:18:09 CEST 2003


"Marcelo A. Camelo" <camelo at esss.com.br> writes:

>> It's got nothing to do with your problem, 
>> but it's usually bad form to use a cast 
>> (especially a C-style cast) when it's not 
>> needed.
>
> Thank you for the reminder. But I do still need 
> it when exporting overloaded methods, don't I? 
> If so, I will make sure my bindings generator 
> only specify the cast when exporting overloaded 
> methods.

You don't need to cast; you can declare a variable of the appropriate
type and assign into that:

     void (*pf)(int, double) = f;
     def("f", pf, ...);

I've been meaning to submit this implicit_cast function (which would
also be safe) to Boost:

     template <class T>
     T implicit_cast(T x) { return x; }

     def("f", implicit_cast<void (*)(int,double)>(f));

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list