Search code examples
c++syntaxbracketscurly-bracesbraces

C++: What does this code do? foo([](){bar();});


I just came across a piece of that I am not able to properly look up on Google. It basically looks like this foo([](){bar();}). Here is what I actually found:

ArduinoOTA.onStart([]() {
    Serial.println("Start");
});

Could someone explain this syntax to me or at least tell me what I'm looking at here?


Solution

  • You're looking for lambda expressions.

    In this case, it seems to be registering an action to be performed on start.