2

I am new in c++11 and 14, and I am wondering why in this case

auto c1 = (bool (*)(int))[](int y) {
    return y%2 == 0;
};

the conversion is successful, but when the lambda function has the default capture type, then the conversion fails?

auto c1 = (bool (*)(int))[=](int y) {
    return y%2 == 0;
};
Vahag Chakhoyan
  • 873
  • 1
  • 10
  • 21
  • 3
    [A capturing lambda cannot decay to a function pointer](https://stackoverflow.com/questions/28746744/passing-capturing-lambda-as-function-pointer) – Cory Kramer Jun 23 '20 at 14:52
  • 2
    `=` is not the "default". If it were, you wouldnt have to write it – molbdnilo Jun 23 '20 at 14:55
  • 1
    The capture usually are stored inside the lambda object itself. If you convert to a simple function pointer, then you won't be able to keep that state. – Guillaume Racicot Jun 23 '20 at 15:02

0 Answers0