trouble with function pointers

I'm not really sure about my syntax here, I'm getting an "expected ;" error. I'm trying to store a pointer to a function in my class.

1
2
3
4
5
6
7
8
class myClass
{
    public:
        void SetCallbackFunction(void* pObj, void (*pFunc)());
    private:
        // this is written incorrectly
        void (*pFunc)() callbackfunc_;
};


If someone could point me in the right direction, I'd appreciate it :)
I find it easier to use a typedef for this.

1
2
3
4
5
6
7
8
9
10
typedef void (*pFunc_t)();

class myClass
{
    public:
        void SetCallbackFunction(void* pObj,pFunc_t pFunc);
    private:
        // this is written correctly
      pFunc_t callbackfunc_;
};
Last edited on
Ah, okay. Just wondering, is there any way to fix that without a typedef? I'll switch to using them though, much easier to read.
Like in your function definition, pFunc is the name. Thus when you are making a variable, you have to use that as the name:

void (*this_is_the_variable_name)();

But yeah, use a typedef, much cleaner.
Topic archived. No new replies allowed.