I have a function pointer declared in my header, like this:
typedef void (intCB)(int );
and I have a class member declared like this:
private:
intCB m_intCB;
In my constructor's initialization list I want to initialize it with 0:
MyClass::MyClass : m_intCB(0)
{
#ifdef SOMETHING
m_intCB = &someOtherFunc;
#endif
}
Only if a specific define is in place, I want to set m_intCB to it, if not I want to keep it on 0. The problem with the above code is that I receive:
error C2436: 'm_intCB' : member function or nested class in constructor initializer list
How can I fix it?
That's not a function pointer, you are missing a *. Try:
typedef void (*intCB)(int);
Your typedef is wrong, it should be typedef void (*intCB)(int );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With