Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBrother Bob

Posted 15 November 2012 - 07:56 AM

If you make Tree::Walk take an std::function<void(Node *)>, you can then do t->Walk([](Node *n){Callback1(n, 77);}). The benefit, as stated above, is that you can pass anything that is callable with a Node-pointer and have no return value: a function pointer, a closure and an old-style function object, and your code doesn't have to know or take special action for the different types of callable objects.

#2Brother Bob

Posted 15 November 2012 - 07:55 AM

If you make Tree::Walk take an std::function<void(Node *)>, then you can then do t->Walk([](Node *n){Callback1(n, 77);}). The benefit, as stated above, is that you can pass anything that is callable with a Node-pointer and have no return value: a function pointer, a closure and an old-style function object, and your code doesn't have to know or take special action for the different types of callable objects.

#1Brother Bob

Posted 15 November 2012 - 07:55 AM

If you make Tree::Walk take an std::function<void(Node *)>, then you can then do t->Walk([](Node *){Callback1(77);}). The benefit, as stated above, is that you can pass anything that is callable with a Node-pointer and have no return value: a function pointer, a closure and an old-style function object, and your code doesn't have to know or take special action for the different types of callable objects.

PARTNERS