Reputation: 96767
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?
Upvotes: 2
Views: 3050
Reputation: 206508
functioin pointer typedef Should be:
typedef void (*intCB)(int); //You missed the *
Upvotes: 1
Reputation:
And:
MyClass::MyClass : m_intCB(0)
should be:
MyClass::MyClass() : m_intCB(0)
Upvotes: 1
Reputation: 14505
Function pointer is a pointer, so don't miss *
typedef void (*intCB)(int);
Upvotes: 2
Reputation: 791421
That's not a function pointer, you are missing a *
. Try:
typedef void (*intCB)(int);
Upvotes: 8