Reputation: 1254
So, I'm looking at one of the codes my professor gave me, but I don't know what the void(*f) means, could anyone clarify?
template<class T>
void BinaryTree<T>::inorder( void (*f)(const T&), BTNode<T> *node ) const //<-- right here
{
if (!node)
return;
inorder(f, node->left);
f(node->elem);
inorder(f, node->right);
}
Upvotes: 0
Views: 423
Reputation: 79491
In C++ a pointer F
to a function that maps type X
to type Y
is denoted as Y (*F)(X)
.
Upvotes: 0
Reputation: 6883
this is afunction pointer. the function gets a unction pointer as parameter.
but since this is already template c++ i would try to avoid this. It would be better to use functors instead. (but may be its a function pointer for a reason)
Upvotes: 0
Reputation: 227438
It is a pointer to a function returning void
, and taking const T&
parameter. The name of the pointer if f
.
void foo(const T&); // a function declaration
void (*f)(const T&); // function pointer
f = &foo; // Can assign &foo to f, return type and signature match
Upvotes: 5