<?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-Kram]]></title><description><![CDATA[<p>Hallo!<br />
Folgendes:</p>
<pre><code>template &lt;class T, int height, int length&gt;
class t_matrix
{
public:
    T array[height][length];
    //...
    //blah blah
    //...
    void print()
    {
        for (int i=0; i&lt;height; i++)
            for (int j=0; j&lt;length; j++)
                array[i][j].print();
    }
};
</code></pre>
<p>So sieht das ganze stark vereinfacht aus.<br />
Das Problem ist, dass der Compiler natürlich nicht wissen kann, ob für die Template-Klasse T eine print()-Funktion existiert, und meckert entsprechend rum. Ich möchte aber nur solche Klassen T verwenden, die eine solche Funktion aufweisen. Wie kann ich das dem Compiler beibringen?<br />
Grüzli,<br />
Krecik</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/154295/template-kram</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 22:43:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/154295.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Jul 2006 00:04:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template-Kram on Wed, 26 Jul 2006 00:05:15 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Folgendes:</p>
<pre><code>template &lt;class T, int height, int length&gt;
class t_matrix
{
public:
    T array[height][length];
    //...
    //blah blah
    //...
    void print()
    {
        for (int i=0; i&lt;height; i++)
            for (int j=0; j&lt;length; j++)
                array[i][j].print();
    }
};
</code></pre>
<p>So sieht das ganze stark vereinfacht aus.<br />
Das Problem ist, dass der Compiler natürlich nicht wissen kann, ob für die Template-Klasse T eine print()-Funktion existiert, und meckert entsprechend rum. Ich möchte aber nur solche Klassen T verwenden, die eine solche Funktion aufweisen. Wie kann ich das dem Compiler beibringen?<br />
Grüzli,<br />
Krecik</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104260</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104260</guid><dc:creator><![CDATA[Krecik]]></dc:creator><pubDate>Wed, 26 Jul 2006 00:05:15 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Kram on Wed, 26 Jul 2006 00:22:38 GMT]]></title><description><![CDATA[<p>Krecik schrieb:</p>
<blockquote>
<p>Das Problem ist, dass der Compiler natürlich nicht wissen kann, ob für die Template-Klasse T eine print()-Funktion existiert, und meckert entsprechend rum. Ich möchte aber nur solche Klassen T verwenden, die eine solche Funktion aufweisen. Wie kann ich das dem Compiler beibringen?</p>
</blockquote>
<p>eigentlich sollte sich der compiler genauso verhalten, wie du willst... d.h. er meckert nur wenn T kein print() hat. Die Template-Klasse wird ja erst kompiliert sobald du eine Instanz davon erstellst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104262</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104262</guid><dc:creator><![CDATA[DrGreenthumb]]></dc:creator><pubDate>Wed, 26 Jul 2006 00:22:38 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Kram on Wed, 26 Jul 2006 01:14:57 GMT]]></title><description><![CDATA[<p>Hmm!<br />
Er sagt syntax error blah blah, und dass er mit dem '.' hinter array[i][j] nichts anfangen kann oder so.<br />
Ich benutze Visual <a href="http://Studio.NET" rel="nofollow">Studio.NET</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104265</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104265</guid><dc:creator><![CDATA[Krecik]]></dc:creator><pubDate>Wed, 26 Jul 2006 01:14:57 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Kram on Wed, 26 Jul 2006 07:30:36 GMT]]></title><description><![CDATA[<p>Für welchen Typ hast du denn das Template ausgeprägt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104306</guid><dc:creator><![CDATA[Mathias]]></dc:creator><pubDate>Wed, 26 Jul 2006 07:30:36 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Kram on Wed, 26 Jul 2006 07:48:54 GMT]]></title><description><![CDATA[<p>*war dumm*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104315</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Wed, 26 Jul 2006 07:48:54 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Kram on Wed, 26 Jul 2006 07:51:58 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

template &lt;class T, int height, int length&gt;
class t_matrix
{
public:
    T array[height][length];
    //...
    //blah blah
    //...
    void print()
    {
        for (int i=0; i&lt;height; i++)
            for (int j=0; j&lt;length; j++)
                array[i][j].print();
    }
};

class test
{
public:
	void print();
};

int main(void)
{
	t_matrix&lt;test, 10, 10&gt; matrix;
	matrix.print();
}
</code></pre>
<p>Works like a charm...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104316</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104316</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 26 Jul 2006 07:51:58 GMT</pubDate></item></channel></rss>