0

I wish to know how to assign a lambda to a function pointer, is this a viable syntax? I tried this:

    const size_t N = 3;
    typedef void (*pf)();
    pf F1 = [=](){ cout << N << endl; }

It fails to compile, saying:

no viable conversion from '(lambda at xxx.cpp:6:3)' to 'pf' (aka 'void (*)()')

Is there a way to do this? Thanks!

Immanuel Kant
  • 517
  • 3
  • 8

0 Answers0