<?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[Typauflösung bei template]]></title><description><![CDATA[<p>Folgendes Problem :</p>
<pre><code class="language-cpp">struct convert_ex
{
	template&lt;typename other_string_type,typename result_string_type&gt;
	result_string_type operator()(const other_string_type &amp;Arg) const
	{
		return result_string_type(Arg.begin(),Arg.end()) ;
	}
};

string Str1=&quot;test&quot; ;
convert_ex aConverter ;
string Str2=aConverter(Str1) ;
</code></pre>
<p>Der Compiler meldet mir den Fehler &quot;error: no match for call to `(convert_ex) (std::string&amp;)'&quot;<br />
Der Compiler müsste doch dies auflösen können, oder liege ich hier komplett falsch.</p>
<p>Besten Dank für eure Bemühungen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/258167/typauflösung-bei-template</link><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 12:06:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/258167.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Jan 2010 12:37:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Typauflösung bei template on Thu, 07 Jan 2010 12:37:53 GMT]]></title><description><![CDATA[<p>Folgendes Problem :</p>
<pre><code class="language-cpp">struct convert_ex
{
	template&lt;typename other_string_type,typename result_string_type&gt;
	result_string_type operator()(const other_string_type &amp;Arg) const
	{
		return result_string_type(Arg.begin(),Arg.end()) ;
	}
};

string Str1=&quot;test&quot; ;
convert_ex aConverter ;
string Str2=aConverter(Str1) ;
</code></pre>
<p>Der Compiler meldet mir den Fehler &quot;error: no match for call to `(convert_ex) (std::string&amp;)'&quot;<br />
Der Compiler müsste doch dies auflösen können, oder liege ich hier komplett falsch.</p>
<p>Besten Dank für eure Bemühungen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1834303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1834303</guid><dc:creator><![CDATA[case]]></dc:creator><pubDate>Thu, 07 Jan 2010 12:37:53 GMT</pubDate></item><item><title><![CDATA[Reply to Typauflösung bei template on Thu, 07 Jan 2010 12:39:37 GMT]]></title><description><![CDATA[<p>Wo soll result_string_type herkommen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1834305</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1834305</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 07 Jan 2010 12:39:37 GMT</pubDate></item><item><title><![CDATA[Reply to Typauflösung bei template on Thu, 07 Jan 2010 12:45:50 GMT]]></title><description><![CDATA[<p>Der Ausdruck &quot;string Str2=aConverter(Str1) ; &quot; sollte doch dem Compiler sagen was ich will ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1834308</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1834308</guid><dc:creator><![CDATA[case]]></dc:creator><pubDate>Thu, 07 Jan 2010 12:45:50 GMT</pubDate></item><item><title><![CDATA[Reply to Typauflösung bei template on Thu, 07 Jan 2010 12:51:24 GMT]]></title><description><![CDATA[<p>case schrieb:</p>
<blockquote>
<p>Der Ausdruck &quot;string Str2=aConverter(Str1) ; &quot; sollte doch dem Compiler sagen was ich will ?</p>
</blockquote>
<p>Nein, zumal Rückgabewerte nicht zwangsweise ausgewertet werden müssen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1834315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1834315</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Thu, 07 Jan 2010 12:51:24 GMT</pubDate></item><item><title><![CDATA[Reply to Typauflösung bei template on Thu, 07 Jan 2010 12:59:52 GMT]]></title><description><![CDATA[<p>asc schrieb:</p>
<blockquote>
<p>case schrieb:</p>
<blockquote>
<p>Der Ausdruck &quot;string Str2=aConverter(Str1) ; &quot; sollte doch dem Compiler sagen was ich will ?</p>
</blockquote>
<p>Nein, zumal Rückgabewerte nicht zwangsweise ausgewertet werden müssen.</p>
</blockquote>
<pre><code class="language-cpp">string Str2=aConverter(Str1) ;
</code></pre>
<p>ist kein Ausdruck, sondern eine Definition. Der initialisierende Ausdruck darin ist</p>
<pre><code class="language-cpp">aConverter(Str1)
</code></pre>
<p>und hieraus kann der Rückgabetyp nicht ermittelt werden. Eine direkte Deduktion des Rückgabetyps erfolgt nur bei Konvertierungsoperatoren - klar, denn hier ist ja die Konvertierung in einen bestimmten Zieltyp überhaupt erst der Grund für den Funktionsaufruf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1834319</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1834319</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 07 Jan 2010 12:59:52 GMT</pubDate></item><item><title><![CDATA[Reply to Typauflösung bei template on Thu, 07 Jan 2010 13:11:33 GMT]]></title><description><![CDATA[<p>Ok, überzeugt.<br />
Dann muss ich mein Problem anders an gehen.<br />
Trotzdem danke..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1834332</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1834332</guid><dc:creator><![CDATA[case]]></dc:creator><pubDate>Thu, 07 Jan 2010 13:11:33 GMT</pubDate></item><item><title><![CDATA[Reply to Typauflösung bei template on Thu, 07 Jan 2010 13:25:19 GMT]]></title><description><![CDATA[<p>du musst den result-Typ in irgendeiner Weise mitgeben, und zwar entweder als Argument (direkt oder indirekt) oder explizit als Templateparameter angeben. Beispiele:</p>
<p>Expliziter templateparameter bei der Funktion</p>
<pre><code class="language-cpp">struct convert_ex
{
    template&lt;typename result_string_type, typename other_string_type&gt; //beachte: result_type zuerst, damit man den zweiten parameter weglassen kann
    result_string_type operator()(const other_string_type &amp;Arg) const
    {
        return result_string_type(Arg.begin(),Arg.end()) ;
    }
};

/*...*/
string Str2=aConverter.operator()&lt;string&gt;(Str1); //eklig, macht den nutzen in der Schreibweise mit op() zunichte
</code></pre>
<p>Expliziter Templateparameter beim struct</p>
<pre><code class="language-cpp">template &lt;class result_string_type&gt;
struct convert_ex
{
    template&lt;typename other_string_type&gt; 
    result_string_type operator()(const other_string_type &amp;Arg) const
    {
        return result_string_type(Arg.begin(),Arg.end()) ;
    }
};

/*...*/
convert_ex&lt;string&gt; aConverter;
string Str2=aConverter(Str1);
MyString Str3 = aConverter(Str1); // FEHLER: convert_ex&lt;string&gt; kann nicht in MyString konvertieren, ein ganz klarer Nachteil!
</code></pre>
<p>Ermitteln des Typs aus einem zusätzlichen Argument:</p>
<pre><code class="language-cpp">struct convert_ex
{
    template&lt;typename result_string_type, typename other_string_type&gt; 
    result_string_type&amp; operator()(const other_string_type &amp;Arg, result_string_type&amp; res) const
    {
        res = result_string_type(Arg.begin(),Arg.end()) ;
        return res;
    }
};

/*...*/
string Str2;
aConverter(Str1, Str2); //Nachteil: keine initialisierung von Str2 sondern eine Zuweisung. Str2 muss bereits bestehen.
</code></pre>
<p>über einen Tag:</p>
<pre><code class="language-cpp">template &lt;typename string_type&gt;
struct StringTypeTag {};

struct convert_ex
{
    template&lt;typename result_string_type, typename other_string_type&gt; 
    result_string_type&amp; operator()(const other_string_type &amp;Arg, StringTypeTag&lt;result_string_type&gt;) const
    {
        return result_string_type(Arg.begin(),Arg.end()) ;
    }
};

/*...*/
string Str2=aConverter(Str1, StringTypeTag&lt;string&gt;());
</code></pre>
<p>Am Einfachsten wäre es wohl als freie Funktion, das wäre von allem etwas:</p>
<pre><code class="language-cpp">template&lt;typename result_string_type, typename other_string_type&gt; //beachte: result_type zuerst, damit man den zweiten parameter weglassen kann
result_string_type ConvertString(const other_string_type &amp;Arg)
{
  return result_string_type(Arg.begin(),Arg.end()) ;
}

/*...*/
string Str2 = ConvertString&lt;string&gt;(Str1);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1834344</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1834344</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 07 Jan 2010 13:25:19 GMT</pubDate></item><item><title><![CDATA[Reply to Typauflösung bei template on Thu, 07 Jan 2010 13:45:28 GMT]]></title><description><![CDATA[<p>Danke pumuckl,</p>
<p>Das bringt mich einen guten Schritt vorwärts.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1834364</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1834364</guid><dc:creator><![CDATA[case]]></dc:creator><pubDate>Thu, 07 Jan 2010 13:45:28 GMT</pubDate></item></channel></rss>