If you want to make it recursive, then you have to capture the lambda (by ref). To do that, you need to give it a named type:
std::function<bool(Graph*, bool*, stack<int>&, int, int)> DepthFirstSearch =
[&](Graph *g, bool *ch, stack<int> &S, int v, int w) {
// bunch of code here that possibly calls DepthFirstSearch
};
You can't just do auto DepthFirstSearch = [=](...){...} here because the lambda will need to know the type of DepthFirstSearch in order to capture it - and if you just use auto then the type won't exist until after the lambda-expression is processed, which is too late. Hence the std::function<...>.
(...);(with the arguments for the call) at the end (after the}) to actually call it. If you want to store it, to call it later, useauto DepthFirstSearch = [](..)...;boolvalue with a lambda expression. Did you mean to invoke the lambda at the end of that expression ([](...) -> bool {...}(<arguments go here>))?