Pregunta

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.

¿Fue útil?

Solución

Try

template <typename T>
void preorder ( void ( *functptr ) (T&) )
{
    preorder(root, functptr);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top