<?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[Fragen zu Lambda-Ausdrücken]]></title><description><![CDATA[<p>Was gibt es für Möglichkeiten, dass folgender Code kompiliert wird:</p>
<p>Linear Algebra.cpp</p>
<pre><code class="language-cpp">const double div = sqrt(s);
matSA.map([div](double x) {return x / div;}); // Fehler
</code></pre>
<p>matrix.cpp</p>
<pre><code class="language-cpp">template &lt;class T&gt;
void Matrix&lt;T&gt;::map(T (*func) (T)) {...}
</code></pre>
<p>matSA ist vom Typ Matrix&lt;double&gt;. Wenn ich im Lambda-Ausdruck das div weglasse wird alles fehlerfrei kompliliert.</p>
<p>Es kommt btw folgender Fehler:</p>
<blockquote>
<p>..\src\Linear Algebra.cpp: In Funktion »int main(int, const char**)«:<br />
..\src\Linear Algebra.cpp:1582:46: Fehler: keine passende Funktion für Aufruf von »Matrix&lt;double&gt;::map(main(int, const char**)::&lt;lambda(double)&gt;)«<br />
..\src\Linear Algebra.cpp:1582:46: Anmerkung: Kandidat ist:<br />
In file included from ..\src\Linear Algebra.cpp:9:0:<br />
..\src\matrix.h:136:8: Anmerkung: void Matrix&lt;T&gt;::map(T (<em>)(T)) [with T = double]<br />
..\src\matrix.h:136:8: Anmerkung: keine bekannte Umwandlung für Argument 1 von »main(int, const char**)::&lt;lambda(double)&gt;« nach »double (</em>)(double)«</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/topic/307135/fragen-zu-lambda-ausdrücken</link><generator>RSS for Node</generator><lastBuildDate>Fri, 07 Aug 2026 18:05:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/307135.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 17 Aug 2012 18:58:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fragen zu Lambda-Ausdrücken on Fri, 17 Aug 2012 21:38:24 GMT]]></title><description><![CDATA[<p>Was gibt es für Möglichkeiten, dass folgender Code kompiliert wird:</p>
<p>Linear Algebra.cpp</p>
<pre><code class="language-cpp">const double div = sqrt(s);
matSA.map([div](double x) {return x / div;}); // Fehler
</code></pre>
<p>matrix.cpp</p>
<pre><code class="language-cpp">template &lt;class T&gt;
void Matrix&lt;T&gt;::map(T (*func) (T)) {...}
</code></pre>
<p>matSA ist vom Typ Matrix&lt;double&gt;. Wenn ich im Lambda-Ausdruck das div weglasse wird alles fehlerfrei kompliliert.</p>
<p>Es kommt btw folgender Fehler:</p>
<blockquote>
<p>..\src\Linear Algebra.cpp: In Funktion »int main(int, const char**)«:<br />
..\src\Linear Algebra.cpp:1582:46: Fehler: keine passende Funktion für Aufruf von »Matrix&lt;double&gt;::map(main(int, const char**)::&lt;lambda(double)&gt;)«<br />
..\src\Linear Algebra.cpp:1582:46: Anmerkung: Kandidat ist:<br />
In file included from ..\src\Linear Algebra.cpp:9:0:<br />
..\src\matrix.h:136:8: Anmerkung: void Matrix&lt;T&gt;::map(T (<em>)(T)) [with T = double]<br />
..\src\matrix.h:136:8: Anmerkung: keine bekannte Umwandlung für Argument 1 von »main(int, const char**)::&lt;lambda(double)&gt;« nach »double (</em>)(double)«</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2242954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2242954</guid><dc:creator><![CDATA[Ramanujan]]></dc:creator><pubDate>Fri, 17 Aug 2012 21:38:24 GMT</pubDate></item><item><title><![CDATA[Reply to Fragen zu Lambda-Ausdrücken on Fri, 17 Aug 2012 19:06:29 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template&lt;typename T, typename Callable&gt;
void Matrix&lt;T&gt;::map(Callable func);
</code></pre>
<p>Wobei dir sicherlich bekannt ist, dass du Definition und Deklaration bei Templates nicht trennen kannst, sodass die Definition ebenfalls in den Header gehört.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2242955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2242955</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Fri, 17 Aug 2012 19:06:29 GMT</pubDate></item><item><title><![CDATA[Reply to Fragen zu Lambda-Ausdrücken on Fri, 17 Aug 2012 20:08:05 GMT]]></title><description><![CDATA[<p>Endlich ein Beitrag, in dem ich mitschreiben kann!</p>
<p><strong>1.</strong> Zitiere ich mal den Standard:</p>
<p>N3337 5.1.2.6 schrieb:</p>
<blockquote>
<p>The closure type for a lambda-expression with no lambda-capture has a public non-virtual non-explicit const<br />
conversion function to pointer to function having the same parameter and return types as the closure type’s<br />
function call operator. The value returned by this conversion function shall be the address of a function<br />
that, when invoked, has the same effect as invoking the closure type’s function call operator.</p>
</blockquote>
<p>Sprich: Du darfst kein Lambda-Capture haben. Hast du aber. Deswegen definiert der closure-Typ logischerweise keinen entsprechenden Konvertierungsoperator für den entsprechenden Zeigertyp (da der closure-Typ dann von scope-lokalen Variablen abhängig wäre).</p>
<p><strong>2.</strong> Sobald du kein Lambda-Capture mehr hast, wäre der einzige Fehler eigentlich noch die Deduzierung. Gib einfach explizit <code>&lt;double&gt;</code> als Template-Parameter an.</p>
<p>Natürlich solltest du aber einfach Michels Variante nehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2242973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2242973</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Fri, 17 Aug 2012 20:08:05 GMT</pubDate></item><item><title><![CDATA[Reply to Fragen zu Lambda-Ausdrücken on Fri, 17 Aug 2012 21:41:58 GMT]]></title><description><![CDATA[<p>Ok, damit wäre alles geklärt, thx.</p>
<p>Edit:<br />
Ne, sry, es klappt doch noch nicht:</p>
<p>in der matrix.h steht nun:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class Matrix {
public:
	//...
	template &lt;class Callable&gt;
	void map(Callable func);
	//...
}

//...

template &lt;class T, class Callable&gt;
void Matrix&lt;T&gt;::map(Callable func) {
	for (int i = 0; i &lt; dim1_; i++)
		for (int j = 0; j &lt; dim2_; j++)
			updateEntry(i, j, func(getEntry(i, j)));
}
</code></pre>
<p>Beim Kompilieren kommen folgende Fehler:</p>
<blockquote>
<p>g++ -O2 -Wall -c -fmessage-length=0 -std=c++11 -o src\Statistik.o ..\src\Statistik.cpp<br />
In file included from ..\src\Statistik.cpp:1:0:<br />
..\src\matrix.h:626:34: Fehler: falsche Benutzung des unvollständigen Typs »class Matrix&lt;T&gt;«<br />
In file included from ..\src\Statistik.cpp:1:0:<br />
..\src\matrix.h:50:7: Fehler: Deklaration von »class Matrix&lt;T&gt;«<br />
..\src\Statistik.cpp: In Funktion »statistik::Analysed statistik::analyse(Matrix&lt;double&gt;&amp;, Matrix&lt;double&gt;&amp;, long long int)«:<br />
..\src\Statistik.cpp:178:20: Fehler: keine passende Funktion für Aufruf von »Matrix&lt;double&gt;::map(&lt;unresolved overloaded function type&gt;)«<br />
..\src\Statistik.cpp:178:20: Anmerkung: Kandidat ist:<br />
In file included from ..\src\Statistik.cpp:1:0:<br />
..\src\matrix.h:137:8: Anmerkung: template&lt;class Callable&gt; void Matrix::map(Callable) [with Callable = Callable; T = double]<br />
..\src\matrix.h:137:8: Anmerkung: Herleitung/Ersetzung von Templateargument gescheitert:<br />
..\src\Statistik.cpp:178:20: Anmerkung: Template-Parameter »Callable« konnte nicht ermittelt werden</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2242988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2242988</guid><dc:creator><![CDATA[Ramanujan]]></dc:creator><pubDate>Fri, 17 Aug 2012 21:41:58 GMT</pubDate></item><item><title><![CDATA[Reply to Fragen zu Lambda-Ausdrücken on Fri, 17 Aug 2012 21:51:40 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template &lt;class T&gt;
template &lt;class Callable&gt;
void Matrix&lt;T&gt;::map(Callable func) {
...
</code></pre>
<p>Es geht um die Definition eines Membertemplates eines Templates; nicht um ein Template mit 2 Parametern.<br />
Das verursacht vermutlich nicht den Fehler, den entsprechenden Code hast du aber nicht gezeigt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2242993</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2242993</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 17 Aug 2012 21:51:40 GMT</pubDate></item><item><title><![CDATA[Reply to Fragen zu Lambda-Ausdrücken on Sat, 18 Aug 2012 18:52:53 GMT]]></title><description><![CDATA[<p>Ja, mit Lambda-Ausdrücken funktioniert es jetzt, allerdings nicht mehr mit Funktionen vom Typ &quot;T (*)(T)&quot;. In der statistik.cpp steht das hier:<br />
erg.eigen.map(sqrt);</p>
<p>erg.eigen ist vom Typ Matrix&lt;double&gt; und sqrt kommt aus cmath.</p>
<p>Die Fehlermeldung steht bereits in meinem letzten Beitrag.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2243178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2243178</guid><dc:creator><![CDATA[Ramanujan]]></dc:creator><pubDate>Sat, 18 Aug 2012 18:52:53 GMT</pubDate></item></channel></rss>