Afficher un message
Vieux 13/04/2008, 23h27   #4
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How do I create a function in my library for passing user callbackfunction

Richard Heathfield wrote:
> Ian Collins said:
>
>> Angus wrote:
>>> Hello
>>>
>>> I am writing a library which will write data to a user defined callback
>>> function. The function the user of my library will supply is:
>>>
>>> int (*callbackfunction)(const char*);
>>>
>>> In my libary do I create a function where user passes this callback
>>> function? How would I define the function?
>>>
>>> I tried this
>>>
>>> callbackfunction clientfunction;
>>>
>>> void SpecifyCallbackfunction(cbFunction cbFn)
>>> {
>>> clientfunction = cbFn;
>>> }
>>>
>>> Then called like this:
>>> clientfunction(sz); // sz is a C-string.
>>>

>> You should be passing the address of the function, not a string.
>>
>> int f( const char* );
>>
>> clientfunction( f );

>
> I doubt it. Since clientfunction is an instance of callbackfunction (and
> presumably the definition of callbackfunction, above, is supposed to be a
> typedef), it takes a const char *, not an int(*)(const char *).
>

OK, I promise never to post pre-caffeine ever again!

I read the OP as passing a string to SpecifyCallbackfunction.

--
Ian Collins.
  Réponse avec citation
 
Page generated in 0,12428 seconds with 9 queries