I have never seen a grammar in C ++ like this before:
typedef int (callback)(int);
what does it really mean? I just find that if I create an operator
callback a;
The effect is very similar to declaring a forward function.
below is the code i wrote
#include<cstdio> int callbackfunc(int i) { printf("%d\n",i); return i*i; } // you can also use typedef int (callback)(int) here! typedef int (*callback)(int); void func(callback hook) { hook(hook(3)); } int main() { func(callbackfunc); getchar(); return 0; }
you can use
typedef int (*callback)(int);
in this code, but if we change it to
typedef int (callback)(int);
it will also give the same result!
and I know typedef int (*callback)(int)
and typedef int (callback)(int)
these are two completely different materials.
source share