I am trying to pass a function pointer to another function with an argument of type T.

Like so:

void preorder ( void ( *functptr ) (T&) ) // preorder traversal of tree
{
    preorder(root, functptr(T));

}

I understand that I need to pass an actual object to the function but this is being passed to another private function that actually knows what function it will be working with and I just need this public method to be a gateway between the two.

有帮助吗?

解决方案

Try

template <typename T>
void preorder ( void ( *functptr ) (T&) )
{
    preorder(root, functptr);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top