I'm trying t write a recursive lambda warped by std::function like this:
function<int(int)> fib {[&](int n) {
assert( n >= 0 );
if( n < 2 ) return val;
else
return fib(n-1) + fib(n-2);
}};
It's worked, but if I change the capture method from '&' to '=', I found this code can be compiled but will core(segmentation fault) at fib init.
That's why?
Thanks in advance :)