[LAD] again [ot] programming c++ problem (functions adresses)

Lars Luthman lars.luthman at gmail.com
Sun Jul 15 19:03:34 UTC 2007


On Sun, 2007-07-15 at 20:52 +0200, Julien Claassen wrote:
> Hi!
>   Sorry to bother again. But I have the following problem I can't solve.
>   I need to wrap some readline-code in my c++-class. Readline has some 
> function-pointers you can set to a function you wrote yourself. So I did. The 
> sinature of my function ALMOST matches that expected by readline, but it 
> complains about the class part of my signature:
> my function:
> char** (Midish_rl::*)(const char*, int, int);
> Readline expects:
> char8* (*)(const char*, int, int);
>   I tired writing a wrapper function, but for that I need some object, I just 
> tried:
> char** wrapper(const char *text, int start, int end)
> {
>   return my_ui.real_function(text,start,end);
> }
>
>   The code is divided between a few files, so I couldn't just a a global 
> object 'my_ui', which was known at all times.

If the Readline callback format does not have a parameter to pass user
data (which is a rather crappy design if that's the case) you have to
use a global variable of some sort. You can declare it 'extern' in a
header that you include in all files that need it, or make it a
singleton class with a static get_instance() member, or some similar
technique.


--ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.linuxaudio.org/pipermail/linux-audio-dev/attachments/20070715/d9dac498/attachment.pgp>


More information about the Linux-audio-dev mailing list