This example shows how to use a lambda expression as a callback
| 43 | |
| 44 | // This example shows how to use a lambda expression as a callback |
| 45 | void callLambda() |
| 46 | { |
| 47 | int foo = 123; |
| 48 | taskTimer |
| 49 | .initializeMs( |
| 50 | taskInterval, |
| 51 | [foo] // capture just foo by value (Note it would be bad to pass by reference as foo would be out of scope when the lambda function runs later) |
| 52 | () // No parameters to the callback |
| 53 | -> void // Returns nothing |
| 54 | { |
| 55 | if(foo == 123) { |
| 56 | debugf("lambda Callback foo is 123"); |
| 57 | } else { |
| 58 | debugf("lambda Callback foo is not 123, crikey!"); |
| 59 | } |
| 60 | }) |
| 61 | .start(); |
| 62 | } |
| 63 | |
| 64 | // This example shows how to use a member function as a callback |
| 65 | void callMemberFunction() |