<?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[anfängerfrage zu teamplates]]></title><description><![CDATA[<p>hi<br />
wenn ich ein teamplate deffinieren will bekomme ich immer einen fehler....<br />
in meinem buch und im internet steht es so wie ich es mache.<br />
cann es an code::blocks oder dem mingw-compiler liegen?</p>
<p>code</p>
<pre><code class="language-cpp">using namespace std;

teamplate&lt;class T&gt;
</code></pre>
<p>error</p>
<pre><code>error: expected constructor, destructor, or type conversion before '&lt;' token
</code></pre>
<p>kann mir bitte jemand helfen?<br />
danke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/274275/anfängerfrage-zu-teamplates</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 17:10:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/274275.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 22 Sep 2010 20:03:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:03:36 GMT]]></title><description><![CDATA[<p>hi<br />
wenn ich ein teamplate deffinieren will bekomme ich immer einen fehler....<br />
in meinem buch und im internet steht es so wie ich es mache.<br />
cann es an code::blocks oder dem mingw-compiler liegen?</p>
<p>code</p>
<pre><code class="language-cpp">using namespace std;

teamplate&lt;class T&gt;
</code></pre>
<p>error</p>
<pre><code>error: expected constructor, destructor, or type conversion before '&lt;' token
</code></pre>
<p>kann mir bitte jemand helfen?<br />
danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956162</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956162</guid><dc:creator><![CDATA[uiop]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:03:36 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:05:27 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">teamplate wird nicht blau, aber template wird blau. tippfehlerchen.
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1956164</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956164</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:05:27 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:09:29 GMT]]></title><description><![CDATA[<p>oh.... peinlich</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956168</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956168</guid><dc:creator><![CDATA[uiop]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:09:29 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:12:19 GMT]]></title><description><![CDATA[<p>ok hatte es jetzt ausprobiert aber das ist es leider nicht gewesen....</p>
<pre><code class="language-cpp">using namespace std;

template&lt;class T&gt;
</code></pre>
<pre><code>error: expected constructor, destructor, or type conversion before '&lt;' token
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1956171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956171</guid><dc:creator><![CDATA[uiop]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:12:19 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:17:27 GMT]]></title><description><![CDATA[<p>Was soll</p>
<pre><code class="language-cpp">template&lt;class T&gt;
</code></pre>
<p>sein? Das kann nicht alleine stehen. Wahrscheinlich willst du danach eine Klasse oder Funktion definieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956175</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956175</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:17:27 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:19:30 GMT]]></title><description><![CDATA[<p>Also das da geht bei mir:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

template&lt;class T&gt;
T doppelt(T x){
	return 2*x;
}

int main(){
	cout&lt;&lt;doppelt(3.14)&lt;&lt;'\n';
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1956176</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956176</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:19:30 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:20:10 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>Was soll</p>
<pre><code class="language-cpp">template&lt;class T&gt;
</code></pre>
<p>sein? Das kann nicht alleine stehen. Wahrscheinlich willst du danach eine Klasse oder Funktion definieren.</p>
</blockquote>
<p>ja</p>
<pre><code class="language-cpp">#ifndef BIT_FUNKTIONEN_H
#define BIT_FUNKTIONEN_H
using namespace std;

template&lt;class T&gt; pair&lt;int,unsigned char*&gt; varToBytearray(T var);

#endif // BIT_FUNKTIONEN_H
</code></pre>
<pre><code class="language-cpp">#include &quot;Bit_Funktionen.h&quot;

using namespace std;

template&lt;class T&gt; pair&lt;int,unsigned char*&gt; varToBytearray(T var){
    pair&lt;int,unsigned char*&gt; back;
    back-&gt;first=sizeof(var);

    unsigned char ar[back-&gt;first];

    for(int i=sizeof(ar)/sizeof(ar[0])-1;i&gt;=0;i++){//geht byte für byte durch
        T zw=var;
        //zw um i bytes nach rechts verschieben
        for(int a=0;a&lt;i;a++){zw=zw&gt;&gt;8;};

        ar[sizeof(ar)/sizeof(ar[0])-1-i]=zw&amp;0xff;//an der 0ten,1. ect stelle einfügen

    };
    back-&gt;second=&amp;ar;

    return back;
};//pair&lt;int,unsigned char*&gt;varToBytearray(T var)
</code></pre>
<p>die funktion soll eine variable als bytearray zurückgeben</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956178</guid><dc:creator><![CDATA[uiop]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:20:10 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:22:47 GMT]]></title><description><![CDATA[<p>ok brauche iostream.......<br />
wieso teamplates aber in diesem header deffiniert sind kann ich mir nicht erklären</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956182</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956182</guid><dc:creator><![CDATA[uiop]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:22:47 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:27:30 GMT]]></title><description><![CDATA[<p>template &lt;typename T&gt; sollte für Funktionen außerhalb einer Klasse funktionieren oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956187</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:27:30 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:27:54 GMT]]></title><description><![CDATA[<p>uiop schrieb:</p>
<blockquote>
<p>ja</p>
</blockquote>
<p>Dann zeig nächstes Mal bitte gleich auf Anhieb den relevanten Code.</p>
<p>Inkludiere den passenden Header. Und verwende <strong>nie</strong> <code>using namespace</code> in Headerdateien, da dadurch der Namensraum für alle Clients irreversibel ausgeleert wird, was ihn ziemlich überflüssig macht.</p>
<pre><code class="language-cpp">#include &lt;utility&gt;

template &lt;typename T&gt;
std::pair&lt;int, unsigned char*&gt; varToByteArray(T var);
</code></pre>
<p>Übrigens werden lokale Variablen am Ende des Blocks zerstört, danach sollten sie nicht mehr referenziert werden. STL-Container (z.B. <code>std::vector</code> ) würden dir die Sache erheblich erleichtern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956188</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956188</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:27:54 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Wed, 22 Sep 2010 20:31:56 GMT]]></title><description><![CDATA[<p>uiop schrieb:</p>
<blockquote>
<p>ok brauche iostream.......</p>
</blockquote>
<p>Was hat das mit deinem Problem zu tun?</p>
<p>uiop schrieb:</p>
<blockquote>
<p>wieso teamplates aber in diesem header deffiniert sind kann ich mir nicht erklären</p>
</blockquote>
<p>Es wurde dir schon gesagt, dass es &quot;Templates&quot; heisst. Und wenn wir schon dabei sind, kannst du auch &quot;definieren&quot; richtig schreiben.</p>
<p>Davon abgesehen habe ich auch bei dieser Aussage nicht verstanden, was du damit meinst. Streng dich bitte ein wenig an, wenn du ernsthafte Hilfe erwartest.</p>
<p>Edit: Ich weiss nicht, ob du das gemeint hast, aber Templates musst du vollständig im Header definieren, wenn sie über mehrere Übersetzungseinheiten hinweg benutzt werden sollen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956190</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956190</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Wed, 22 Sep 2010 20:31:56 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Thu, 23 Sep 2010 11:42:31 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>uiop schrieb:</p>
<blockquote>
<p>ok brauche iostream.......</p>
</blockquote>
<p>Was hat das mit deinem Problem zu tun?</p>
<p>uiop schrieb:</p>
<blockquote>
<p>wieso teamplates aber in diesem header deffiniert sind kann ich mir nicht erklären</p>
</blockquote>
<p>Es wurde dir schon gesagt, dass es &quot;Templates&quot; heisst. Und wenn wir schon dabei sind, kannst du auch &quot;definieren&quot; richtig schreiben.</p>
<p>Davon abgesehen habe ich auch bei dieser Aussage nicht verstanden, was du damit meinst. Streng dich bitte ein wenig an, wenn du ernsthafte Hilfe erwartest.</p>
<p>Edit: Ich weiss nicht, ob du das gemeint hast, aber Templates musst du vollständig im Header definieren, wenn sie über mehrere Übersetzungseinheiten hinweg benutzt werden sollen.</p>
</blockquote>
<p>Ich vermute dass genau das sein Fehler ist, weil die Fehlermeldung kommt mir sehr bekannt vor <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Falls du Deklaration und Definition trotzdem trenne willst, dann nehm für die Templatedefinition ne andere Dateiendung wie zum Beispiel .impl<br />
Jedoch musst du dann diese in den Header inkludieren, also gerade anders rum als bei normalen Klassen zum Beispiel.</p>
<p>Lg freeG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956396</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956396</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Thu, 23 Sep 2010 11:42:31 GMT</pubDate></item><item><title><![CDATA[Reply to anfängerfrage zu teamplates on Thu, 23 Sep 2010 12:05:01 GMT]]></title><description><![CDATA[<p>uiop schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#ifndef BIT_FUNKTIONEN_H
#define BIT_FUNKTIONEN_H
using namespace std;

template&lt;class T&gt; pair&lt;int,unsigned char*&gt; varToBytearray(T var);

#endif // BIT_FUNKTIONEN_H
</code></pre>
</blockquote>
<p>Pfui! Das &quot;using namespace std;&quot; hat in einem Header <em>nichts</em> zu suchen.</p>
<p>Getrennte Übersetzung bei Templates gibt es auch nicht wirklich. Du musst entweder auch die Definition in den Header packen (das klappt auch garantiert ohne &quot;multiple definition&quot; Fehler) <strong>oder</strong> Du musst in Deiner Übersetzungseinheit all die Varianten für T, die dein restliches Programm benötigt, manuell über folgende Syntax erzeugen:</p>
<pre><code class="language-cpp">// cpp-file

template&lt;class T&gt; pair&lt;int,unsigned char*&gt; varToBytearray(T var)
{
  ...
}

// &quot;explicit template instantiation&quot;
template pair&lt;int,unsigned char*&gt; varToBytearray&lt;int&gt;(int);
template pair&lt;int,unsigned char*&gt; varToBytearray&lt;double&gt;(double);
template pair&lt;int,unsigned char*&gt; varToBytearray&lt;short&gt;(short);
</code></pre>
<p>Die letzten drei Zeilen veranlassen den Compiler, die Funktionsschablone von oben für drei Varianten (T=int, T=double, T=short) zu übersetzen.</p>
<p>Desweiteren würde ich dieses Design (damit meine ich jetzt das Funktionstemplate an sich) auch vermeiden. Es sieht so aus, als ob Du dynamisch Speicher anlegen willst und einen Zeiger darauf zurückgibst. Das führt besonders bei C++ schnell mal zu Speicherlecks. ein std::vector&lt;unsigned char&gt; wäre hier vielleicht angebrachter, oder eine Funktion, die einen Output-Iterator übergeben bekommt und die Daten über diesen einfach ablegt.</p>
<p>kk</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956405</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Thu, 23 Sep 2010 12:05:01 GMT</pubDate></item></channel></rss>