<?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[template funktion kann nicht richtig gefunden werden]]></title><description><![CDATA[<p>ich habe die Funktionen</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
int ArraysFunctions::ArrayCenterPos(vector&lt;T&gt; &amp; InArray, T threshold)
{
	return ArraysFunctions::ArrayCenterPos(&amp;InArray[0], (int)InArray.size(), threshold);
}

template&lt;typename T&gt;
int ArraysFunctions::ArrayCenterPos(complex&lt;T&gt;* InArray, int size, T threshold)
{
...
}

template&lt;typename T&gt;
int ArraysFunctions::ArrayCenterPos(T * InArray, int size, T threshold)
{
...
}
</code></pre>
<p>die allerdings bei einem Aufruf mit T = vector&lt;complex&lt;double&gt;&gt; den Fehler auswirft:</p>
<blockquote>
<p>1&gt;.\src\LaserData.cpp(349) : error C2780: 'int ArraysFunctions::ArrayCenterPos(T *,int,T)' : expects 3 arguments - 2 provided<br />
1&gt; h:\Dev\CPP\SVN\modelocksimulation\ModelockingSimulation2\include\matthias\Common\ExtFunctions.h(47) : see declaration of 'ArraysFunctions::ArrayCenterPos'<br />
1&gt;.\src\LaserData.cpp(349) : error C2782: 'int ArraysFunctions::ArrayCenterPos(std::vector&lt;T&gt; &amp;,T)' : template parameter 'T' is ambiguous<br />
1&gt; h:\Dev\CPP\SVN\modelocksimulation\ModelockingSimulation2\include\matthias\Common\ExtFunctions.h(46) : see declaration of 'ArraysFunctions::ArrayCenterPos'<br />
1&gt; could be 'double'<br />
1&gt; or 'std::complex&lt;double&gt;'</p>
</blockquote>
<p>an der Stelle</p>
<pre><code class="language-cpp">vector&lt;complex&lt;double&gt; &gt; timeArray;
...
int maxpos = ArrayCenterPos(timeArray, 250.0);
</code></pre>
<p>wie bringe ich den Compiler dazu die richtige Funktion zu wählen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/241526/template-funktion-kann-nicht-richtig-gefunden-werden</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 10:54:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/241526.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 21 May 2009 20:19:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to template funktion kann nicht richtig gefunden werden on Thu, 21 May 2009 20:19:29 GMT]]></title><description><![CDATA[<p>ich habe die Funktionen</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
int ArraysFunctions::ArrayCenterPos(vector&lt;T&gt; &amp; InArray, T threshold)
{
	return ArraysFunctions::ArrayCenterPos(&amp;InArray[0], (int)InArray.size(), threshold);
}

template&lt;typename T&gt;
int ArraysFunctions::ArrayCenterPos(complex&lt;T&gt;* InArray, int size, T threshold)
{
...
}

template&lt;typename T&gt;
int ArraysFunctions::ArrayCenterPos(T * InArray, int size, T threshold)
{
...
}
</code></pre>
<p>die allerdings bei einem Aufruf mit T = vector&lt;complex&lt;double&gt;&gt; den Fehler auswirft:</p>
<blockquote>
<p>1&gt;.\src\LaserData.cpp(349) : error C2780: 'int ArraysFunctions::ArrayCenterPos(T *,int,T)' : expects 3 arguments - 2 provided<br />
1&gt; h:\Dev\CPP\SVN\modelocksimulation\ModelockingSimulation2\include\matthias\Common\ExtFunctions.h(47) : see declaration of 'ArraysFunctions::ArrayCenterPos'<br />
1&gt;.\src\LaserData.cpp(349) : error C2782: 'int ArraysFunctions::ArrayCenterPos(std::vector&lt;T&gt; &amp;,T)' : template parameter 'T' is ambiguous<br />
1&gt; h:\Dev\CPP\SVN\modelocksimulation\ModelockingSimulation2\include\matthias\Common\ExtFunctions.h(46) : see declaration of 'ArraysFunctions::ArrayCenterPos'<br />
1&gt; could be 'double'<br />
1&gt; or 'std::complex&lt;double&gt;'</p>
</blockquote>
<p>an der Stelle</p>
<pre><code class="language-cpp">vector&lt;complex&lt;double&gt; &gt; timeArray;
...
int maxpos = ArrayCenterPos(timeArray, 250.0);
</code></pre>
<p>wie bringe ich den Compiler dazu die richtige Funktion zu wählen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1713932</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1713932</guid><dc:creator><![CDATA[pospiech]]></dc:creator><pubDate>Thu, 21 May 2009 20:19:29 GMT</pubDate></item><item><title><![CDATA[Reply to template funktion kann nicht richtig gefunden werden on Fri, 22 May 2009 01:10:29 GMT]]></title><description><![CDATA[<p>In dem du dem Kompiler auch eine Funktion gibst, die er auswählen kann. Du willst wohl, dass er diese Funktion aufruft, oder?</p>
<pre><code class="language-cpp">int ArraysFunctions::ArrayCenterPos(vector&lt;T&gt; &amp; InArray, T threshold)
</code></pre>
<p>Mal schauen was du übergibst:</p>
<pre><code>1. Argument Typ: vector&lt;complex&lt;double&gt; &gt;
2. Argument Typ: double
</code></pre>
<p>Daraus folgt, dass der Template Parameter <code>T</code> zwei Typen ist? Nämlich entweder <code>double</code> oder <code>complex&lt;double&gt;</code> . Das kann ja nicht gehen!</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1713986</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1713986</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Fri, 22 May 2009 01:10:29 GMT</pubDate></item><item><title><![CDATA[Reply to template funktion kann nicht richtig gefunden werden on Fri, 22 May 2009 05:59:33 GMT]]></title><description><![CDATA[<p>Stimmt, das habe ich jetzt hoffentlich durch ein</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
int ArraysFunctions::ArrayCenterPos(vector&lt;complex&lt;T&gt;&gt; InArray, T threshold)
{
	return ArraysFunctions::ArrayCenterPos(&amp;InArray[0], (int)InArray.size(), threshold);
}
</code></pre>
<p>gelöst.</p>
<p>Aber ich habe zusätzlich das Problem das in einem solchen Fall nicht die richtige Funktion in der Funktion aufgerufen wird.</p>
<p>Hier beim Kompilieren am Beispiel der Funktion</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
int ArraysFunctions::ArrayMaxPos(vector&lt;T&gt; const &amp; InArray)
{	
	return ArraysFunctions::ArrayMaxPos(&amp;InArray[0], (int)InArray.size());
}

template&lt;typename T&gt;
int ArraysFunctions::ArrayMaxPos(complex&lt;T&gt;* InArray, int size)
{	
...
}

template&lt;typename T&gt;
int ArraysFunctions::ArrayMaxPos(T * InArray, int size)
{	
...
}
</code></pre>
<p>Wenn die oberste Funktion aufgerufen wird mit T = complex&lt;double&gt;, dann muss die Funktion mit complex&lt;T&gt; aufgerufen werden nicht die mit T.</p>
<p>Das macht der Kompiler aber nicht:</p>
<blockquote>
<p>1&gt;h:\Dev\CPP\SVN\modelocksimulation\ModelockingSimulation2\include\matthias\Common\ExtFunctions.h(337) : error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::complex&lt;double&gt;' (or there is no acceptable conversion)<br />
1&gt; C:\Programme\Microsoft Visual Studio 8\VC\include\complex(744): could be 'std::complex&lt;double&gt;::_Myt &amp;std::complex&lt;double&gt;::operator =&lt;double&gt;(const std::complex&lt;double&gt; &amp;)'<br />
1&gt; C:\Programme\Microsoft Visual Studio 8\VC\include\complex(679): or 'std::complex&lt;double&gt; &amp;std::complex&lt;double&gt;::operator =(const std::complex&lt;double&gt;::_Ty &amp;)'<br />
1&gt; C:\Programme\Microsoft Visual Studio 8\VC\include\complex(712): or 'std::complex&lt;double&gt;::_Myt &amp;std::complex&lt;double&gt;::operator =(const std::complex&lt;double&gt;::_Myt &amp;)'<br />
1&gt; while trying to match the argument list '(const std::complex&lt;double&gt;, const std::complex&lt;double&gt;)'<br />
1&gt; h:\Dev\CPP\SVN\modelocksimulation\ModelockingSimulation2\include\matthias\Common\ExtFunctions.h(308) : see reference to function template instantiation 'int ArraysFunctions::ArrayMaxPos&lt;const std::complex&lt;double&gt;&gt;(T *,int)' being compiled<br />
1&gt; with<br />
1&gt; [<br />
1&gt; T=const std::complex&lt;double&gt;<br />
1&gt; ]<br />
1&gt; .\src\LaserDisturb.cpp(72) : see reference to function template instantiation 'int ArraysFunctions::ArrayMaxPos&lt;std::complex&lt;double&gt;&gt;(const std::vector&lt;_Ty&gt; &amp;)' being compiled<br />
1&gt; with<br />
1&gt; [<br />
1&gt; _Ty=std::complex&lt;double&gt;<br />
1&gt; ]</p>
</blockquote>
<p>hier wird das letzte Funktionstemplate mit T=complex&lt;double&gt; genutzt, was aber nicht funktioneren kann. Daher die ersten paar operator Fehlermeldungen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1714000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1714000</guid><dc:creator><![CDATA[pospiech]]></dc:creator><pubDate>Fri, 22 May 2009 05:59:33 GMT</pubDate></item><item><title><![CDATA[Reply to template funktion kann nicht richtig gefunden werden on Fri, 22 May 2009 12:32:18 GMT]]></title><description><![CDATA[<p>Grundsätzlich ist es wieder das gleiche Problem, du gibst dem Kompiler nicht die richtigen Möglichkeiten.<br />
<code>&amp;InArray[0]</code> gibt ein <code>std::complex&lt;double&gt; const*</code> zurück. Die Funktion, welche du aufrufen möchtest, erwartet aber ein <code>std::complex&lt;double&gt;*</code> . Also ein Zeiger auf ein nicht konstantes Objekt. Daher passt die Funktion ganz sicher nicht. Von der Signatur würde aber die letzte Funktion passen mit <code>T</code> als <code>std::complex&lt;double&gt; const*</code> . Du gibst dem Kompiler also schon wieder keine passende Funktion. Allerdings sollten die doch sowieso alle konstant sein?</p>
<p>Allerdings frage ich mich auch ein wenig was du da eigentlich machen willst.<br />
Zum einen: Wieso willst du die Fälle unterscheiden?<br />
Zum anderen: Wieso verwendest du nicht das Iteratorenkonzept?<br />
Zum letzten: Wieso verwendest du nicht die Standardbibliothek für Algorithmen?</p>
<p>Zum Beispiel:<br />
<a href="http://www.cplusplus.com/reference/algorithm/max_element/" rel="nofollow">http://www.cplusplus.com/reference/algorithm/max_element/</a><br />
Gibt dir die Position, bzw. den Iterator, vom maximalsten Element.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1714157</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1714157</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Fri, 22 May 2009 12:32:18 GMT</pubDate></item></channel></rss>