<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[C++11: LambdaFunktionen]]></title><description><![CDATA[<p>Warum geht folgendes nicht?</p>
<pre><code class="language-cpp">class T
{
int i;
void foo()
{
 .... [i](int j) {return i == j;} ...
}
};
</code></pre>
<p>Das Problem scheint zu sein, dass ich auf eine Membervariable zugreife: VC++ meldet a lambda capture variable must be from an enclosing function scope<br />
requires the compiler to capture 'this' but the current default capture mode does not allow it</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/291279/c-11-lambdafunktionen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 17 Aug 2026 20:33:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/291279.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 14 Aug 2011 16:04:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C++11: LambdaFunktionen on Sun, 14 Aug 2011 16:04:52 GMT]]></title><description><![CDATA[<p>Warum geht folgendes nicht?</p>
<pre><code class="language-cpp">class T
{
int i;
void foo()
{
 .... [i](int j) {return i == j;} ...
}
};
</code></pre>
<p>Das Problem scheint zu sein, dass ich auf eine Membervariable zugreife: VC++ meldet a lambda capture variable must be from an enclosing function scope<br />
requires the compiler to capture 'this' but the current default capture mode does not allow it</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2106043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2106043</guid><dc:creator><![CDATA[buuuuuuuu]]></dc:creator><pubDate>Sun, 14 Aug 2011 16:04:52 GMT</pubDate></item><item><title><![CDATA[Reply to C++11: LambdaFunktionen on Sun, 14 Aug 2011 16:11:05 GMT]]></title><description><![CDATA[<p>Geht es denn wenn du i durch this-&gt;i ersetzt oder dir eine lokale Variable in der Funktion anlegst, also int i_temp=i und dann i durch i_temp ersetzt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2106048</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2106048</guid><dc:creator><![CDATA[Max3000]]></dc:creator><pubDate>Sun, 14 Aug 2011 16:11:05 GMT</pubDate></item><item><title><![CDATA[Reply to C++11: LambdaFunktionen on Sun, 14 Aug 2011 16:16:25 GMT]]></title><description><![CDATA[<p>&quot;der dir eine lokale Variable in der Funktion anlegst, also int i_temp=i und dann i durch i_temp ersetzt?&quot; -&gt; Dann geht es, ist aber nicht elegant.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2106054</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2106054</guid><dc:creator><![CDATA[buuuuuuuu]]></dc:creator><pubDate>Sun, 14 Aug 2011 16:16:25 GMT</pubDate></item><item><title><![CDATA[Reply to C++11: LambdaFunktionen on Sun, 14 Aug 2011 16:19:56 GMT]]></title><description><![CDATA[<p>Capture <code>this</code> statt <code>i</code> (möglicherweise musst du dann mit <code>this-&gt;i</code> darauf zugreifen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2106056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2106056</guid><dc:creator><![CDATA[ipsec]]></dc:creator><pubDate>Sun, 14 Aug 2011 16:19:56 GMT</pubDate></item><item><title><![CDATA[Reply to C++11: LambdaFunktionen on Sun, 14 Aug 2011 16:51:27 GMT]]></title><description><![CDATA[<p>Lies dir dazu mal den Abschnitt &quot;capture clause&quot; auf <a href="http://msdn.microsoft.com/en-us/library/dd293603.aspx" rel="nofollow">Lambda Expression Syntax</a> durch und schau dir mal das entsprechende Beispiel auf <a href="http://msdn.microsoft.com/en-us/library/dd293599.aspx" rel="nofollow">Examples of Lambda Expressions</a> an.</p>
<p>Grüsse</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2106068</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2106068</guid><dc:creator><![CDATA[durchlesen]]></dc:creator><pubDate>Sun, 14 Aug 2011 16:51:27 GMT</pubDate></item><item><title><![CDATA[Reply to C++11: LambdaFunktionen on Mon, 15 Aug 2011 08:19:12 GMT]]></title><description><![CDATA[<p>Man darf nur lokale Variablen in der Capture-Clause benennen und this. i ist keine lokale Variable. i ist nur die Kurzform von this-&gt;i. Verwendest Du <code>=</code> oder `this` in der Capture-Clause, wird der Wert des this-Zeigers kopiert. Um eine Kopie von <em>i</em> im Lambda-Objekt zu speichern, gibt es folgenden Workaround:</p>
<pre><code class="language-cpp">auto&amp; z = i;
[z](int j) {return z==j;};
</code></pre>
<p>Mit der ersten Zeile wird z als &quot;lokales Synonym&quot; zu i definiert. Das darf in der Capture-Clause auftauchen. Das z im Funktionskörper des Lambda-Ausdrucks bezieht sich auf eine Kopie. Mir gefällt das auch nicht, dass man einen Umweg über eine lokale Referenz machen muss. Aber wir können es jetzt nicht mehr ändern. Zumindest nicht bis zur nächsten C++-Version. Ich kann mir gut vorstellen, dass in der nächsten C++ Version (&quot;C++1y&quot;) die Capture-Clause flexibler wird und man in dieser Situation nicht diese lästige lokale Referenz einfügen muss und dafür direkt i benennen kann. Hoffentlich bekommen wir dann neben &quot;capture by copy&quot; und &quot;capture by reference&quot; auch ein &quot;capture by move&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2106115</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2106115</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Mon, 15 Aug 2011 08:19:12 GMT</pubDate></item></channel></rss>