|
Boost Users : |
Subject: Re: [Boost-users] boost::bind for C function
From: Philipp Kraus (philipp.kraus_at_[hidden])
Date: 2012-12-20 21:46:44
Am 21.12.2012 um 02:32 schrieb Lars Viklund:
> On Fri, Dec 21, 2012 at 12:30:20AM +0100, Philipp Kraus wrote:
>> Hello,
>>
>> I have got a a C library function call, which defines a function:
>> typedef int (*CFunction) (State* K);
>>
>> So I would like to use boost::bind / boost::function to create the binding
>> to a class method:
>>
>> boost::function<CFunction>( boost::bind(&MyClass::myMethod, this) )
>>
>> so that I can use the class method with the CFunction signature.
>> I would like to call a class method with the object context like a
>> C function.
>>
>> Can anybody help me to create a correct binding?
> You have several horrible choices for getting a free function pointer
> from something like this.
>
> Stateless C++11 lambdas can be coerced into a free function pointer, but
> as they're stateless, they will not fly here.
Thanks for this long description. I think my option without C++11 is to define
a global pointer to "this" and define a static function, that uses this stored
pointer.
Phil
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net