Search code examples
c++dbus

What's the meaning of this C++ syntax


I found this c++ code but I can't understand this syntax:

auto path_dbus = [&](DBus::Connection &bus) {
    ...
};

Solution

  • It is a lambda function that:

    • captures any used variables by reference [&]
    • takes an argument (DBus::Connection&)
    • does some work {...}

    To break down that line:

    auto path_dbus = [&]      (DBus::Connection &bus) {... };
                     ^capture ^arguments              ^work