c++ - Function parameter - pointer or reference to a pointer? -


void deletechildren(bstnode *node) {     // recurse left down tree...     if(node->hasleftchild()) deletechildren(node->getleftchild());     // recurse right down tree...     if(node->hasrightchild()) deletechildren(node->getrightchild());      // clean data @ node.     node->cleardata(); // assume deletes internal data      // free memory used node itself.     delete node; }  // call external code. deletechildren(rootnode); 

this function deleting bst recursively.

i got question first line, bstnode *node , should modify bstnode *& node ?

no, pointers passed value, you're in essence "copying" pointer when pass parameter. pass reference when want callee modify parameter in caller.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -