Code: Select all
auto lambda = [&](int& p) -> double {
}
Code: Select all
clangDer
Fehler: Keine passende Funktion für Aufruf eines Objekts vom Typ „(Lambda bei Linenum:Spalte)“
und die Clang-Erklärung:
Code: Select all
source.cpp: note: candidate function not viable: cannot convert argument of incomplete type 'void' to 'int &' (aka 'int &') for 1st argument
507 | auto lambda = [&](int& p) -> double {
^
Code: Select all
auto lambda1 = [](auto &l, auto &r) -> double {
return (l.x - l.x) * (l.x - l.x) + r.z;
};
Die Lambda-Funktion wird nie aufgerufen. Warum leitet der Compiler etwas ab? Warum ist es void, wenn ich explizit int geschrieben habe? Ich verstehe die Bedeutung des Compiler-Warntexts überhaupt nicht.
Kann mir das jemand erklären?
P.S. Ich weiß, es ist zu viel für eine Frage, aber es ist so Ist es in Ordnung, alles zu erfassen - [&]?
Update
Danke Ahmed und andere Kommentatoren. Als ich ein minimal reproduzierbares Beispiel mit einem (https://onlinegdb.com/zVj8XiVH-)[onlinegdb.com] erstellt habe, wurde deutlich sichtbar, dass die Lambda-Definition mit einem ; geendet haben muss, etwa so:
Code: Select all
auto lambda = []() {} ;