Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C2436 member function or nested class in constructor initializer list

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?

like image 908
Geo Avatar asked Feb 28 '26 03:02

Geo


2 Answers

That's not a function pointer, you are missing a *. Try:

typedef void (*intCB)(int);
like image 89
CB Bailey Avatar answered Mar 01 '26 17:03

CB Bailey


Your typedef is wrong, it should be typedef void (*intCB)(int );

like image 33
Asha Avatar answered Mar 01 '26 18:03

Asha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!