can anybody explain below lamda function syntax ?
-
thread = QThread::create([=](){ counting_memberFUnction(); });
actually i not get understand why lamda function written like below
[=](){ counting_memberFUnction(); });
-
@SimonSchroeder means [this] will work instead of [=].
yes i am confused at syntax [=].
@Qt-embedded-developer
[this]
is sufficient (and better) if you only need to access class members (variables or methods) in the lambda code.[=]
givesthis
too, but also all local variables (passed by value, not reference) in the function where the lambda is defined. It is "convenient" but "lazy". You can instead always choose explicitly to put it all local variables and/orthis
to pass just the specified ones, which is "better" coding style.That is what
[=]
does. Note that there is a similar[&]
which does just the same thing but passes the local variables by reference instead. -
thread = QThread::create([=](){ counting_memberFUnction(); });
actually i not get understand why lamda function written like below
[=](){ counting_memberFUnction(); });
@Qt-embedded-developer said in can anybody explain below lamda function syntax ?:
actually i not get understand why lamda function written like below
Because this is the lambda syntax defined by the c++ standard.
-
thread = QThread::create([=](){ counting_memberFUnction(); });
actually i not get understand why lamda function written like below
[=](){ counting_memberFUnction(); });
Hi,
I wrote this explanation some years ago
[...]
is the scope/what is captured from current class to make it visible inside the lambda body (content).
( ... )
in there are parameters to the function itself.
{ ... }
lambda body, containing the actual code which runs on execution. -
thread = QThread::create([=](){ counting_memberFUnction(); });
actually i not get understand why lamda function written like below
[=](){ counting_memberFUnction(); });
@Qt-embedded-developer said in can anybody explain below lamda function syntax ?:
actually i not get understand why lamda function written like below
Which part of the lambda confuses you? Using
[=]
looks like laziness. It would be better (with the little code you provide) just to capturethis
which would be sufficient. -
@Qt-embedded-developer said in can anybody explain below lamda function syntax ?:
actually i not get understand why lamda function written like below
Which part of the lambda confuses you? Using
[=]
looks like laziness. It would be better (with the little code you provide) just to capturethis
which would be sufficient.@SimonSchroeder means [this] will work instead of [=].
yes i am confused at syntax [=].
-
@SimonSchroeder means [this] will work instead of [=].
yes i am confused at syntax [=].
@Qt-embedded-developer
[this]
is sufficient (and better) if you only need to access class members (variables or methods) in the lambda code.[=]
givesthis
too, but also all local variables (passed by value, not reference) in the function where the lambda is defined. It is "convenient" but "lazy". You can instead always choose explicitly to put it all local variables and/orthis
to pass just the specified ones, which is "better" coding style.That is what
[=]
does. Note that there is a similar[&]
which does just the same thing but passes the local variables by reference instead. -