C++ function pointer as a static member

c++, function-pointers

Solution

I introduced a typedef, which made it somewhat clearer in my opinion:

class A
{
  typedef void (*FPTR)(int a, char c);

  static FPTR cb;
};

A::FPTR A::cb = NULL;

Problem

I cannot figure the syntax to declare a function pointer as a static member. ``` #include <iostream> using namespace std; class A { static void (*cb)(int a, char c); }; void A::*cb = NULL; int main() { } ``` g++ outputs the error "cannot declare pointer to `void' member". I assume I need to do something with parentheses but void A::(*cb) = NULL does not work either.

Original source