Cryptic C ++ "thing" (function pointer)

What is this syntax for C ++? Can someone point me to a technical term so that I can see if I find anything in my text?

At first I thought it was a prototype, but then =they (*fn)threw me away ...

Here is my example:

void (*fn) (int&,int&) = x;
+3
source share
9 answers

It can be rewritten in

typedef void (*T) (int&, int&);
T fn = x;

The 2nd statement is obvious that this issue should have been resolved = x;. In the first statement, we do Tas a type synonym void(*)(int&, int&), which means:

  • function pointer ( (*…))
  • return void
  • and takes 2 arguments int&, int&.
+14
source

int, . fn x.

+9

.

fn :

void pointedToFunction(int&, int&)

fn , x.

:

int a;
int b;
(*fn)(a,b);

int a;
int b;
pointedToFunction(a,b);
+2

, int void.

0

, . fn. x, , , , .

0

, 2 void. x .

0

, =.

:

typedef void func_t(int&,int&);

, :

typedef func_t *fn_t;

:

 fn_t fn = ...;
0

Source: https://habr.com/ru/post/1743842/


All Articles