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.
|