How to call a recursive linked list traversal function in C++ -


i have function:

    void traverserecursive ( node * head, void (*visit) (node *) )     {       if ( head != nullptr )       {         visit( head ) ;         traverserecursive( head->next, visit ) ;       }     } 

and i'm trying call in main.cpp with

traverserecursive ( head, traverserecursive ) ; 

which gives me error "argument of type "void (*)(node *head, void (*visit)(node ))" incompatible parameter of type "void ()(node *)" "

so how correctly call it? learning linked lists , don't understand what

 void (*visit) (node *) 

means @ all.

void (*visit) (node *) 

means "pointer function taking 1 argument of type node* , returning void". traverserecurive takes 2 argumenst , therefore of different type. need define function like

void dosomething(node* n) { } 

and pass traverserecursive


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -