C ++ function pointer as a static member

I cannot imagine the syntax for declaring 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 ++ throws the error "cannot declare a pointer to` void 'member ". I suppose I need to do something with parentheses, but void A :: (* cb) = NULL does not work either.

+5
source share
2 answers

I introduced a typedef that made this a little clearer in my opinion:

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

  static FPTR cb;
};

A::FPTR A::cb = NULL;
+28
source
void (*A::cb)(int a, char c) = NULL;
+10
source