Consider the following more simple example:
void fn1(int a)
{
}
fn1 is a function that takes a single int paramter.
Now take a look at fn2:
//Same as typing void fn2(int (*b)())
void fn2(int b())
{
}
Here fn2 does not take in an int, but it takes in a function that returns an int.
Now if you wanted to declare fn1 you could type it like so:
void fn1(int);//ommit the parameter name
And you can also declare fn2 like so:
void fn2(int());
Example usage:
#include <iostream>
int a()
{
sd::cout<<"hi"<<std::endl;
return 0;
}
void fn2(int b())
{
b();
}
int main(int argc, char **argv)
{
fn1(3);
fn2(a);
}
Output will be:
hi
Now there is one more topic to understand... You can forward declare functions with scope.
a.cpp:
void a()
{
void c();
c();
}
//void b()
//{
// c();//<--- undeclared identifier
//}
int main(int argc, char**argv)
{
a();
return 0;
}
c.cpp
#include <iostream>
void c()
{
std::cout<<"called me"<<std::endl;
}
g++ a.cpp c.cpp
./a.out
Output will be:
Called me
And tying it all together. If you do this:
int main(int argc, char**argv)
{
int b();
return 0;
}
You are forward declaring a function called b() that returns type int and takes no parameters
If you would have done b = 3; then you'd get a compiling error as you can't assign a value to a forward declared function.
And once you've read all that it becomes clear:
Foo x(Bar());
You are forward declaring a function x that returns a type Foo and takes in a parameter to a function that returns a type Bar.