<?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[Frage zu template]]></title><description><![CDATA[<p>Hallo wie kann ich hier ein Template rumbauen wenn ich auch den vector verwenden will?</p>
<pre><code class="language-cpp">class STORAGE
{
public:
        int pos;
        string name;
        STORAGE(int p, string n) : pos(p),name(n) {}
};
vector&lt;STORAGE&gt;Box;
</code></pre>
<p>Ich hab schon etwas rumprobiert aber ich kenne hier nicht die Syntax. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Ich dachte erst es könnte so gehen:</p>
<pre><code class="language-cpp">template &lt;class T&gt;
class STORAGE
{
public:
        int pos;
        string name;
        STORAGE(int p, string n) : pos(p),name(n) {}
};
template &lt;class T&gt;
STORAGE&lt;T&gt;::vector&lt;STORAGE&gt;Box;
</code></pre>
<p>Aber da sagt der Compiler: Deklaration nicht abgeschlossen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/310900/frage-zu-template</link><generator>RSS for Node</generator><lastBuildDate>Tue, 04 Aug 2026 05:35:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/310900.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 22 Nov 2012 12:30:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 12:30:34 GMT]]></title><description><![CDATA[<p>Hallo wie kann ich hier ein Template rumbauen wenn ich auch den vector verwenden will?</p>
<pre><code class="language-cpp">class STORAGE
{
public:
        int pos;
        string name;
        STORAGE(int p, string n) : pos(p),name(n) {}
};
vector&lt;STORAGE&gt;Box;
</code></pre>
<p>Ich hab schon etwas rumprobiert aber ich kenne hier nicht die Syntax. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Ich dachte erst es könnte so gehen:</p>
<pre><code class="language-cpp">template &lt;class T&gt;
class STORAGE
{
public:
        int pos;
        string name;
        STORAGE(int p, string n) : pos(p),name(n) {}
};
template &lt;class T&gt;
STORAGE&lt;T&gt;::vector&lt;STORAGE&gt;Box;
</code></pre>
<p>Aber da sagt der Compiler: Deklaration nicht abgeschlossen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2273360</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273360</guid><dc:creator><![CDATA[temp_late]]></dc:creator><pubDate>Thu, 22 Nov 2012 12:30:34 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 12:32:26 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /><br />
Das ist eigentlich kein Problem, aber du musst dich schon für einen Typen entscheiden. Was soll der Code denn für einen Sinn haben? Du nutzt T ja nicht mal in deiner Klasse!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2273361</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273361</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Thu, 22 Nov 2012 12:32:26 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 12:34:34 GMT]]></title><description><![CDATA[<p>was du schreibst sieht so aus als wüsstest du nichtwas du 1. machst und 2. vorhast.</p>
<p>wenn du eine klasse hast und darauf ein klassentemplate machen willst (sprich diese klasse parametrisieren) dann schreibst du einfach einfach anstelle von</p>
<pre><code>class Foo
{
// ...
};
</code></pre>
<p>das hier</p>
<pre><code>template &lt;typename T&gt;
class Foo
{
// ...
};
</code></pre>
<p>ob du dieses template dan auch verwendest ist ne andere sache.<br />
und mit nem vector hat das auch erstmal nichts zu tun.<br />
denn benutzen kannst du diese klasse wie gewohnt.</p>
<pre><code>template &lt;typename T&gt;
class Foo
{
// ...
};

...

int main()
{
    std::vector&lt; Foo&lt;double&gt; &gt; vec;
    // ...
    return 0x0;
}
</code></pre>
<p>aber wenn ich ganz ehrlich bin verstehe ich deine frage nicht wirklich, bzw dein anliegen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2273363</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273363</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Thu, 22 Nov 2012 12:34:34 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 12:48:05 GMT]]></title><description><![CDATA[<p>Hi, lies dir mal bitte die beiden Links in meiner Signatur durch - und stell uns <strong>danach</strong> eine etwas ausführlichere Frage, in der du uns erklärst, was du erreichen willst. Das ist nämlich alles andere als klar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2273372</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273372</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 22 Nov 2012 12:48:05 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 12:48:50 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Du nutzt T ja nicht mal in deiner Klasse!</p>
</blockquote>
<p>Das Stimmt, ich habe T da auch noch nicht benutzt da ich Schritt für Schritt an die Sache rangegangen bin.</p>
<p>Das hier wollte ich aus Spass mit templates basteln:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
using namespace std;

class STORAGE
{
public:
        int pos;
        string name;
         STORAGE(int p, string n) : pos(p),name(n) {}
};
vector&lt;STORAGE&gt;Box;

class GET : STORAGE
{
public:
       GET( int p, string n) : STORAGE(p,n) {}
       void SetName(int p, string n);
       string GetName(int p);
};

void GET :: SetName(int p, string n)
{
       Box.push_back( STORAGE(p,n) );
}

string GET :: GetName(int p)
{
unsigned i=0;
        for( ; i&lt;Box.size();i++)
        {
                if ( Box[i].pos == p )
                {
                   break;
                }
        }
return Box[i].name;
}

int main()
{
GET g(0,&quot;0&quot;);

g.SetName(1,&quot;abc&quot;);
g.SetName(2,&quot;def&quot;);
g.SetName(3,&quot;ghi&quot;);

cout &lt;&lt; &quot;Name: &quot; &lt;&lt; g.GetName ( 1 ) &lt;&lt; &quot;\n&quot;;
cout &lt;&lt; &quot;Name: &quot; &lt;&lt; g.GetName ( 2 ) &lt;&lt; &quot;\n&quot;;
cout &lt;&lt; &quot;Name: &quot; &lt;&lt; g.GetName ( 3 ) &lt;&lt; &quot;\n&quot;;

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2273373</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273373</guid><dc:creator><![CDATA[temp_late]]></dc:creator><pubDate>Thu, 22 Nov 2012 12:48:50 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 12:54:34 GMT]]></title><description><![CDATA[<p>temp_late schrieb:</p>
<blockquote>
<p>Das hier wollte ich aus Spass mit templates basteln:</p>
</blockquote>
<p>Und was verstehst du unter &quot;mit templates basteln&quot;?<br />
Was willst du erreichen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2273377</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273377</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Thu, 22 Nov 2012 12:54:34 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 12:55:54 GMT]]></title><description><![CDATA[<p>1.- globale variable(n)<br />
2.- rad neu erfunden<br />
3.- sinn?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2273380</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273380</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Thu, 22 Nov 2012 12:55:54 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 13:09:53 GMT]]></title><description><![CDATA[<p>Ich will einfach etwas mit templates üben, wie man gerade merkt hab ich davon nämlich nicht wirklich Ahnung.</p>
<p>Ich habe mir vor einiger Zeit diesen Artikel durchgelesen: <a href="http://www.cplusplus.com/doc/tutorial/templates/" rel="nofollow">http://www.cplusplus.com/doc/tutorial/templates/</a></p>
<p>Und jetzt experimentiere ich halt selber etwas rum.</p>
<p>So funktioniert es schon mal:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
using namespace std;

template&lt;class T&gt;
class STORAGE
{
public:
        T pos;
        T name;
         STORAGE(T p, T n) : pos(p),name(n) {}
};
vector&lt;STORAGE&lt;int&gt; &gt;Box;

int main()
{

Box.push_back( STORAGE&lt;int&gt;(8,99) );

cout &lt;&lt; Box[0].pos &lt;&lt; endl;
cout &lt;&lt; Box[0].name &lt;&lt; endl;

return 0;
}
</code></pre>
<p>Aber ich will das so haben:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
using namespace std;

template&lt;class T, class Z&gt;
class STORAGE
{
public:
        T pos;
        T name;
         STORAGE(T p, T n) : pos(p),name(n) {}
};
vector&lt;STORAGE&lt;int,string&gt; &gt;Box;

int main()
{

Box.push_back( STORAGE&lt;int,string&gt;(8,&quot;abc&quot;) );

cout &lt;&lt; Box[0].pos &lt;&lt; endl;
cout &lt;&lt; Box[0].name &lt;&lt; endl;

return 0;
}
</code></pre>
<p>Keine Übereinstimmung für 'STORAGE&lt;int,string&gt;::STORAGE(int,char *)' gefunden</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> Was mach ich da falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2273390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273390</guid><dc:creator><![CDATA[temp_late]]></dc:creator><pubDate>Thu, 22 Nov 2012 13:09:53 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 13:14:53 GMT]]></title><description><![CDATA[<p>Dein Konstruktor will 2 T-Parameter.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2273395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273395</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Thu, 22 Nov 2012 13:14:53 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 13:39:02 GMT]]></title><description><![CDATA[<p>-.-<br />
[cpp]STORAGE(<strong>T</strong> p, <strong>T</strong> n) : pos(p),name(n) {}[/cpp]</p>
<p>Habs jetzt ^^ Danke für eure Hilfe:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
using namespace std;

template&lt;class T, class Z&gt;
class STORAGE
{
public:
         T pos;
         Z name;
          STORAGE(T p, Z n) : pos(p),name(n) {}
};
 vector&lt;STORAGE&lt;int,string&gt; &gt;Box;

int main()
{

 Box.push_back( STORAGE&lt;int,string&gt;(8,&quot;abc&quot;) );

 cout &lt;&lt; Box[0].pos &lt;&lt; endl;
 cout &lt;&lt; Box[0].name &lt;&lt; endl;

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2273405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273405</guid><dc:creator><![CDATA[temp_late]]></dc:creator><pubDate>Thu, 22 Nov 2012 13:39:02 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 14:52:45 GMT]]></title><description><![CDATA[<p>Eine letzte Frage hab ich noch:</p>
<p>Angenommen ich habe folgendes:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class FOO
{
public:
        void print_para(T a);
        void SayHello();
};

template&lt;class T&gt; void FOO&lt;T&gt; :: print_para ( T a )
{

}

template&lt;class T&gt; void FOO&lt;T&gt;:: SayHello()
{
        cout&lt;&lt;&quot;Hello&quot;;
}
</code></pre>
<p>Um eine Funktion aus der Klasse aufzurufen muss ich ja hier jetzt diesen template Kram immer schreiben.</p>
<p>Meine Memberfunktion SayHello verwendet hier ja keinerlei Parameter.</p>
<p>Aber damit ich diese ausführen kann muss ich ja schreiben:</p>
<pre><code class="language-cpp">template&lt;class T&gt; void FOO&lt;T&gt;:: SayHello()
{
        cout&lt;&lt;&quot;Hello&quot;;
}
</code></pre>
<p>Gibts auch irgendwie eine möglichkeit in meiner Klasse Templates verwenden zu können und trotzdem einfach diese Schreibweise einzuhalten?</p>
<pre><code class="language-cpp">void FOO :: SayHello()
{
        cout&lt;&lt;&quot;Hello&quot;;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2273440</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273440</guid><dc:creator><![CDATA[temp_late]]></dc:creator><pubDate>Thu, 22 Nov 2012 14:52:45 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu template on Thu, 22 Nov 2012 14:57:18 GMT]]></title><description><![CDATA[<p>Das hat mit ausführen nur bedingt zu tun - es geht einfach um die Definition. Und nein, die Definition von Klassentemplate-Methoden muss immer so geschehen wie du es gelernt hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2273444</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2273444</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 22 Nov 2012 14:57:18 GMT</pubDate></item></channel></rss>