Ich erwarte, dass die Definition von x aus C++20 veraltet ist und sich nicht kompilieren lässt, aber sie scheint in g++ (GCC) 8.1.0 zu funktionieren. Weiß jemand, ob ich etwas falsch mache?
In Visual Studio 2017 schlägt der Compiler mit einem Fehler um die Definition von y fehl.
Fehler C3791: „Dies“ kann nicht explizit erfasst werden, wenn der Standarderfassungsmodus „Kopieren“ ist (=)
Live Code
Code: Select all
#include
struct X {
void f()
{
int value = 3;
auto x = [=] { // Deprecated from C++20:
return value + g();
};
auto y = [=, this] { // Recommended method from C++20:
return value + g(); // [=] The this pointer will not be captured, so capture with specifying this
};
}
int g() const
{
return 2;
}
};
int main()
{
X().f();
}
Mobile version