how to use a pointer to function?

I'm trying to understand my colleagues' codes in which a function fn is defined in the following way:

1
2
3
4
fn() {
...
return creator(instanceId, attributes, SafeMath);
}


Here creator is a pointer to another function. Can we directly use this pointer in the above way? Actually, I expect something like the code snippet below, that is, the pointer creator is de-referenced at first before its call to the function which it points to:

1
2
3
4
fn() {
...
return (*creator)(instanceId, attributes, SafeMath);
}
Last edited on
If creator is a pointer to function, then the expression creator(instanceId, attributes, SafeMath) is a function call expression. No need to dereference.

ยง5.2.2[expr.call]/1
A function call is a postfix expression followed by parentheses [...] the postfix expression shall be either an lvalue that refers to a function [...] or it shall have pointer to function type
Cubbi, thank you!
Topic archived. No new replies allowed.