<?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[Templateproblem]]></title><description><![CDATA[<p>Hi, die variable shit wird nicht ausgegeben. Brauch ich nen überladungsoperator?</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

	template &lt;class t&gt;
	t rechner (t test1) {
		t shit;
		for (typename t :: iterator i=test1.begin (); i!=test1.end (); i++) {
		shit++;
		}
		return shit;
	}
int main () {

	string bs = &quot;Hallo&quot;;
	string out = rechner (bs);
	cout &lt;&lt; out;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/322037/templateproblem</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 16:57:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/322037.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 04 Dec 2013 11:05:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 11:05:14 GMT]]></title><description><![CDATA[<p>Hi, die variable shit wird nicht ausgegeben. Brauch ich nen überladungsoperator?</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

	template &lt;class t&gt;
	t rechner (t test1) {
		t shit;
		for (typename t :: iterator i=test1.begin (); i!=test1.end (); i++) {
		shit++;
		}
		return shit;
	}
int main () {

	string bs = &quot;Hallo&quot;;
	string out = rechner (bs);
	cout &lt;&lt; out;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2369698</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369698</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 04 Dec 2013 11:05:14 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 11:10:15 GMT]]></title><description><![CDATA[<p>Sag mal, was denkst du, soll wohl der Inkrement-Operator bei <code>std::string</code> machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369700</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369700</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 04 Dec 2013 11:10:15 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 12:51:15 GMT]]></title><description><![CDATA[<p>Inkrementoperator? Bin mir nicht sicher was du damit meinst. Zeile 8 in der Schleifendefinition? Also die schleife soll solange laufen, wie es buchstaben im string gibt.</p>
<p>Oder meinst du t shit wird als string angesehen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369727</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369727</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 04 Dec 2013 12:51:15 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 12:52:01 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>Inkrementoperator? Bin mir nicht sicher was du damit meinst.</p>
</blockquote>
<p>Er meint das hier: shit++;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369728</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 04 Dec 2013 12:52:01 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 12:54:50 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>Oder meinst du t shit wird als string angesehen?</p>
</blockquote>
<p>Was ist denn t deiner Meinung nach hier?</p>
<p>P.S.: &quot;Wird nicht ausgegeben&quot;? Ist das wirklich die Fehlerbeschreibung, die du hier geben willst? Mit welchem Compiler hast du den Code übersetzt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369730</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369730</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 04 Dec 2013 12:54:50 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 14:03:18 GMT]]></title><description><![CDATA[<p>Nene. kompiliert nicht, mit der begrüdung, die Acroth nannte: inkrementoperator.</p>
<p>Dachte der compiler kommt von selbst drauf den richtigen datentypen zu definieren, da es sich bei so einem operator um einen datentyp handeln sollte der dazu fähig ist.</p>
<p>Und wie loest man das Problem? Nen int als zusätzlichen Parameter der ausgegeben wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369734</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369734</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 04 Dec 2013 14:03:18 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 14:08:30 GMT]]></title><description><![CDATA[<p>Der Compiler kommt schon darauf, was t sein soll. Schließlich übergibst du ein Objekt vom Typ t.</p>
<p>Was willst du überhaupt erreichen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369735</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369735</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 04 Dec 2013 14:08:30 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 14:11:51 GMT]]></title><description><![CDATA[<blockquote>
<p>Und wie loest man das Problem?</p>
</blockquote>
<p>Ich weiss nicht, wie man dir klar macht: Was du machst ist quatsch. Wo soll der Operator ++ auf einem std::string definiert sein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369736</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 04 Dec 2013 14:11:51 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 14:29:42 GMT]]></title><description><![CDATA[<p>Das Template soll von main einen String übergeben bekommen. Dieser string soll als schleifenwiederholungsanzahl fungieren. Pro schleife wird dann der inkrementoperator in anspruch genommen um die gesamtbuchstabenlänge als des strings, als zahl auszugeben. Das ergebnis soll zu main zurückgegeben werden und der variablen &quot;out&quot; gespeichert werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369740</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369740</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 04 Dec 2013 14:29:42 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 14:23:33 GMT]]></title><description><![CDATA[<p>1. Du weißt schon, dass man die Länge eines strings auch einfacher bekommen kann?<br />
2. warum als template? für welche Typen soll das denn sonst noch sinnvoll angewendet werden?<br />
3. Die Zählvariable ist nicht vom Typ t, sondern size_t</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369743</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369743</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 04 Dec 2013 14:23:33 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 14:23:56 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>Pro schleife wird dann der inkrementoperator in anspruch genommen um die gesamtbuchstabenlänge des strings auszugeben.</p>
</blockquote>
<p>Du weichst aus. Der <code>operator++</code> auf einem ganzen String ist nicht sinnvoll, was soll deiner Meinung nach passieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369744</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Wed, 04 Dec 2013 14:23:56 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 14:25:57 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>Der <code>operator++</code> auf einem ganzen String ist nicht sinnvoll, was soll deiner Meinung nach passieren?</p>
</blockquote>
<p>So, wie ich ihn inzwischen verstehe, will er die Buchstaben in dem übergebenen string zählen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369745</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369745</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 04 Dec 2013 14:25:57 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 15:33:29 GMT]]></title><description><![CDATA[<p>Hier etwas bearbeitet. Der compiler meckert nicht mehr wegen dem inkrementoperator sondern wegen der zeile 17.<br />
Wenn ich aus dem int ein string mache kommt die selbe meldung: no matching function for call to 'rechner( ..</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/34965">@felix</a> der code hat keinen tieferen sinn. Ist nur übung</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

	template &lt;class t&gt;
	t rechner (t test1, t test2) {
		for (typename t :: iterator i=test1.begin (); i!=test1.end (); i++) {
		test2++;
		}
		return test2;
	}

int main () {

	string bs = &quot;Hallo&quot;;
	int anzahl = 0;
	int out = rechner (bs, anzahl);
	cout &lt;&lt; out;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2369763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369763</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 04 Dec 2013 15:33:29 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 15:31:32 GMT]]></title><description><![CDATA[<p>Was soll t denn in deinem Beispiel sein? int oder std::string?</p>
<p>Ehrlich egsagt, ich habe das Gefühl, dass Templates noch etwas zu hoch für dich sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369766</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 04 Dec 2013 15:31:32 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 15:36:30 GMT]]></title><description><![CDATA[<p>t ist doch das, was ich übergebe oder? In diesem fall einmal string und einmal int. Und der int soll zurückgegeben werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369769</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 04 Dec 2013 15:36:30 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 15:38:20 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>t ist doch das, was ich übergebe oder? In diesem fall einmal string und einmal int. Und der int soll zurückgegeben werden.</p>
</blockquote>
<p>t ist <strong>ein</strong> Typ. Der kann nicht sowohl int als auch string sein.</p>
<p>Templates werden zur Kompilierzeit aufgelöst, d.h. anstelle von &quot;t&quot; wird der Typ der jeweiligen Instanziierung eingesetzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369771</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369771</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 04 Dec 2013 15:38:20 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 15:45:44 GMT]]></title><description><![CDATA[<pre><code>template &lt;typename T, typename T2&gt;
    T2 rechner (T const&amp; test1, T2 test2) 
    {
        return test2 += test1.size();
    }
</code></pre>
<p>Halbwegs richtig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369774</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369774</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 04 Dec 2013 15:45:44 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 15:51:27 GMT]]></title><description><![CDATA[<p>Achso! Gibts denn sowas wie &lt;class t, class x&gt; ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369778</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369778</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 04 Dec 2013 15:51:27 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 15:52:53 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>Achso! Gibts denn sowas wie &lt;class t, class x&gt; ?</p>
</blockquote>
<p>Ja, natürlich. <code>typename</code> und <code>class</code> sind in diesem Fall identisch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369779</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369779</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 04 Dec 2013 15:52:53 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 17:49:18 GMT]]></title><description><![CDATA[<p>Und auf dem weg gehts nicht?<br />
Die Fehlermeldung sagt cant convert x to x. Also braucht man nen übeadungskonstruktor?</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

	template &lt;class t, class t2&gt;
	t rechner (t test1, t2 test2) {
		for (typename t :: iterator i=test1.begin (); i!=test1.end (); i++) {
		test2++;
		}
		return test2;
	}
int main () {

	string bs = &quot;Hallo&quot;;
	int anzahl = 0;
	int out = rechner (bs, anzahl);
	cout &lt;&lt; out;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2369829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369829</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 04 Dec 2013 17:49:18 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 18:03:37 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>Und auf dem weg gehts nicht?<br />
Die Fehlermeldung sagt cant convert x to x. Also braucht man nen übeadungskonstruktor?</p>
</blockquote>
<p>...nein.<br />
Du gibst test2 zurück. Welcher Typ ist das? Und welcher Typ wird von deiner Funktion zurückgegeben?<br />
Templates sind definitiv noch zu hoch für dich.<br />
Schreib erstaml eine Funktion nur für std::string.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369835</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369835</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Wed, 04 Dec 2013 18:03:37 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 20:10:45 GMT]]></title><description><![CDATA[<p>Pfff zeile 7 int statt t. Ansonsten ist alles richtig!!!! Danke leute</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369852</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369852</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Wed, 04 Dec 2013 20:10:45 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 20:14:40 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>Pfff zeile 7 int statt t. Ansonsten ist alles richtig!!!! Danke leute</p>
</blockquote>
<p>Nein, ist es nicht.<br />
Was ist, wenn t2 nicht kompatibel ist mit int?<br />
Und wieso muss die anzahl als Parameter übergeben werden, obwohl der Parameter gar nicht verwendet wird?<br />
Schreib es erstmal nur für std::string.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369853</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369853</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Wed, 04 Dec 2013 20:14:40 GMT</pubDate></item><item><title><![CDATA[Reply to Templateproblem on Wed, 04 Dec 2013 21:14:18 GMT]]></title><description><![CDATA[<p>Der letzte Code erinnert mich irgendwie an so schöne Funktionen in der Art:</p>
<pre><code>void foo(int i)
{
  for (i = 0; i &lt; 5; ++i)
    cout &lt;&lt; &quot;Bar!&quot;;
}
</code></pre>
<p>Schon öfters so gesehen.</p>
<p>Vielleicht lernt der Threadersteller aus diesem Beispiel sogar, was bei ihm falsch läuft.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369867</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369867</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 04 Dec 2013 21:14:18 GMT</pubDate></item></channel></rss>