As mentioned by @Arkadiy in the comments, a stateful lambda does not decay to a function pointer. The fix is to write your traverseInOrder
as a template that takes a callable object
template<class Func>
void traverseInOrder(Func visitFunc)) {
traverseInOrder(visitFunc, root);
}
Alternatively, you could be more type-safe and give it a signature that takes a std::function
that returns void
and takes a node<T>*
void traverseInOrder(std::function<void(node<T>*)> visitFunc)) {
traverseInOrder(visitFunc, root);
}