Pointer function and non-pointer function

Given a print function:
1
2
3
4
void print(int i)
{
    cout << i << endl;
}

Why are we allowed to do this in the main function:
1
2
void (*bar)(int);
bar = &print;

But not this:
1
2
void fizz(int);
fizz = print;

But when it comes to function parameters, we can pass a pointer to a function or a copy of the function:
1
2
3
4
5
6
7
8
9
void foo(void (*f)(int))
{
    (*f)(1);
}

void test(void f(int))
{
    f(1);
} 

Anyone know the reason for these differences?
There is no difference between foo and test:
https://ideone.com/EWDfLF

Functions are not first-class citizens. The weirdness is inherited from C.
Functions are not first-class citizens.


Can you elaborate on that a bit? I haven't heard of that before. Does it mean that functions are inherently (speaking in terms of order of operation) going to be called after pointers to functions?
It means that unlike other things (such as integers, strings, etc) functions aren't treated as value types. They have unusual treatment compared to all other parts of the language.
Topic archived. No new replies allowed.