I’m trying to assign a function to a variable without the function declaration.
So this code is OK (compiling):
void foo(void) {
a++;
}
typedef void (*tCallBack)();
tCallBack cb;
cb = &foo;
However this code has extra lines and not very readable as the action declared in the separate place (outside of main). So I’d like to do something like this:
typedef void (*tCallBack)();
tCallBack cb;
cb = [](){ a++; };
But the compiller throws an error: Error: Expected an expression in “main.cpp”, Line: 254, Col: 25
The syntax {} is taken from wikipedia and should work for C++ 11 and above. As I know - MBED uses C++ 11 so it should work.
Any thoughts?