| re: declaring a function pointer variable
"lou zion" <illuzioner@adelphia.net> wrote in message
news:E8idnSUoy9yyOoLfRVn-oQ@adelphia.com...[color=blue]
> hi all,
>
> i've got a class that takes a parameterless function pointer as a
> parameter. i want to store that function pointer in a variable and i'm
> trying to figure out the syntax. i came up with the stuff below, but it's
> telling me it can't convert from void *(void) to void(void), which i
> didn't think i was doing. what's the proper syntax for defining and
> initializing a function pointer like this?
>
> thnks a bunch,
>
> lou
>
> class TabWatcher : public QObject
> {
> public:
> TabWatcher( const char * name = 0, QWidget * NewFocusWidget = 0, void
> *funcptr()=0 ) ;
> ~TabWatcher();
>
> protected:
> void (*FuncPtr)();
>
> }
>
>
> TabWatcher::TabWatcher( const char * name, QWidget * NewFocusWidget, void
> *funcptr()) : QObject(parent,0),
> newfocus(NewFocusWidget),
> FuncPtr(funcptr)
> {
>
> }
>[/color]
I find it quite useful to define a type for my function pointers. It makes
constructing the declarations much easier. For example,
typedef void (*VOIDFUNC_TYPE)();
....
void bar() {...}
....
void foo( VOIDFUNC_TYPE funptr ) {...}
....
foo(bar);
-Howard |