cj1094
cj1094

Reputation: 81

c++ void* with references within parameter list

void printFunc( void(*)(int&,int&), int& );

I don't know what this code does. I know it's a function prototype with two parameters, but I don't know what the first parameter means.

Upvotes: 0

Views: 151

Answers (2)

It's a pointer to a function which takes two int& parameters and returns void.

If there was an identifier for it (let's say p), it would be spelled like this:

void (*p)(int&, int&)

Then, we can apply the principle "if we type the declaration as an expression, we get its type." So:

  1. (*p) means p is a pointer

  2. (*p)(int&, int&) means (*p) is a function taking two int& parameters

  3. void (*p)(int&, int&) means it returns void.

Upvotes: 0

Joseph Mansfield
Joseph Mansfield

Reputation: 110648

The first parameter type is a pointer to a function that takes two arguments, both int&s, and returns void.

void foo(int&, int&);

If you have this function declaration, you could pass foo as an argument to printFunc.

Upvotes: 2

Related Questions