<?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[Änfängerproblem bei klassen-template]]></title><description><![CDATA[<p>Hallo</p>
<p>ich möchte eine klasse matrix basteln<br />
diese soll wie z.b. der vector mit: Matrix&lt;double&gt; testmatrix; erstellt werden.<br />
dazu benötige ich templates<br />
nun hab ich ein bissesl gegoogled und einige schöne Howtos gefunden<br />
aber scheinbar bin ich zu blöde</p>
<pre><code class="language-cpp">#ifndef MATRIX_H_
#define MATRIX_H_

//template&lt;class MatTyp&gt;

//template&lt;typename MatTyp&gt; // das funzt net, warum ????
class Matrix
{
	private:
		unsigned long m;// sicherstellen das m*n nicht überlaufen kann z.b.(sqrt &lt; max(unsigned long))
		unsigned long n;
		void* matrix; // über template
	public:
		Matrix();
		Matrix(unsigned long m, unsigned long n);
		virtual ~Matrix();
		Matrix operator +(Matrix op2);
		Matrix operator -(Matrix op2);
		Matrix operator *(Matrix op2);
		Matrix operator /(Matrix op2);
};

#endif /*MATRIX_H_*/
</code></pre>
<p>mein void* matrix soll eigentlich MatTyp* matrix sein</p>
<p>aber sobald ich den template-befehl einsetze bekomme ich folgende fehlermeldung</p>
<pre><code>../src/Matrix.cpp:4: Fehler: »template&lt;class MatTyp&gt; class Matrix« ohne Template-Parameter verwendet
../src/Matrix.cpp:4: Fehler: ISO-C++ verbietet Deklaration von »Matrix« ohne Typ
../src/Matrix.cpp: In function »int Matrix()«:
../src/Matrix.cpp:4: Fehler: »int Matrix()« als andere Symbolart redeklariert
../src/Matrix.h:7: Fehler: vorherige Deklaration von »template&lt;class MatTyp&gt; class Matrix«
../src/Matrix.cpp: At global scope:
../src/Matrix.cpp:9: Fehler: expected constructor, destructor, or type conversion before »::« token
../src/Matrix.cpp:13: Fehler: »template&lt;class MatTyp&gt; class Matrix« ohne Template-Parameter verwendet
../src/Matrix.cpp:13: Fehler: ISO-C++ verbietet Deklaration von »Matrix« ohne Typ
../src/Matrix.cpp: In function »int Matrix(long unsigned int, long unsigned int)«:
../src/Matrix.cpp:13: Fehler: »int Matrix(long unsigned int, long unsigned int)« als andere Symbolart redeklariert
../src/Matrix.h:7: Fehler: vorherige Deklaration von »template&lt;class MatTyp&gt; class Matrix«
../src/Matrix.cpp:15: Fehler: »m« wurde in diesem Gültigkeitsbereich nicht definiert
../src/Matrix.cpp:16: Fehler: »n« wurde in diesem Gültigkeitsbereich nicht definiert
../src/Matrix.cpp: At global scope:
../src/Matrix.cpp:21: Fehler: ungültige Verwendung des Template-Namens »Matrix« ohne eine Argumentliste
make: *** [src/Matrix.o] Fehler 1
</code></pre>
<p>kann mir hier jemand weiterhelfen?</p>
<p>kennt jemand ein gutes howto zu templates mit klassen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/213366/änfängerproblem-bei-klassen-template</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 07:21:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/213366.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 May 2008 22:54:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Änfängerproblem bei klassen-template on Fri, 16 May 2008 22:54:15 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>ich möchte eine klasse matrix basteln<br />
diese soll wie z.b. der vector mit: Matrix&lt;double&gt; testmatrix; erstellt werden.<br />
dazu benötige ich templates<br />
nun hab ich ein bissesl gegoogled und einige schöne Howtos gefunden<br />
aber scheinbar bin ich zu blöde</p>
<pre><code class="language-cpp">#ifndef MATRIX_H_
#define MATRIX_H_

//template&lt;class MatTyp&gt;

//template&lt;typename MatTyp&gt; // das funzt net, warum ????
class Matrix
{
	private:
		unsigned long m;// sicherstellen das m*n nicht überlaufen kann z.b.(sqrt &lt; max(unsigned long))
		unsigned long n;
		void* matrix; // über template
	public:
		Matrix();
		Matrix(unsigned long m, unsigned long n);
		virtual ~Matrix();
		Matrix operator +(Matrix op2);
		Matrix operator -(Matrix op2);
		Matrix operator *(Matrix op2);
		Matrix operator /(Matrix op2);
};

#endif /*MATRIX_H_*/
</code></pre>
<p>mein void* matrix soll eigentlich MatTyp* matrix sein</p>
<p>aber sobald ich den template-befehl einsetze bekomme ich folgende fehlermeldung</p>
<pre><code>../src/Matrix.cpp:4: Fehler: »template&lt;class MatTyp&gt; class Matrix« ohne Template-Parameter verwendet
../src/Matrix.cpp:4: Fehler: ISO-C++ verbietet Deklaration von »Matrix« ohne Typ
../src/Matrix.cpp: In function »int Matrix()«:
../src/Matrix.cpp:4: Fehler: »int Matrix()« als andere Symbolart redeklariert
../src/Matrix.h:7: Fehler: vorherige Deklaration von »template&lt;class MatTyp&gt; class Matrix«
../src/Matrix.cpp: At global scope:
../src/Matrix.cpp:9: Fehler: expected constructor, destructor, or type conversion before »::« token
../src/Matrix.cpp:13: Fehler: »template&lt;class MatTyp&gt; class Matrix« ohne Template-Parameter verwendet
../src/Matrix.cpp:13: Fehler: ISO-C++ verbietet Deklaration von »Matrix« ohne Typ
../src/Matrix.cpp: In function »int Matrix(long unsigned int, long unsigned int)«:
../src/Matrix.cpp:13: Fehler: »int Matrix(long unsigned int, long unsigned int)« als andere Symbolart redeklariert
../src/Matrix.h:7: Fehler: vorherige Deklaration von »template&lt;class MatTyp&gt; class Matrix«
../src/Matrix.cpp:15: Fehler: »m« wurde in diesem Gültigkeitsbereich nicht definiert
../src/Matrix.cpp:16: Fehler: »n« wurde in diesem Gültigkeitsbereich nicht definiert
../src/Matrix.cpp: At global scope:
../src/Matrix.cpp:21: Fehler: ungültige Verwendung des Template-Namens »Matrix« ohne eine Argumentliste
make: *** [src/Matrix.o] Fehler 1
</code></pre>
<p>kann mir hier jemand weiterhelfen?</p>
<p>kennt jemand ein gutes howto zu templates mit klassen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1510815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1510815</guid><dc:creator><![CDATA[stfischr]]></dc:creator><pubDate>Fri, 16 May 2008 22:54:15 GMT</pubDate></item><item><title><![CDATA[Reply to Änfängerproblem bei klassen-template on Fri, 16 May 2008 23:04:45 GMT]]></title><description><![CDATA[<p>Zeig mal die zugehörige cpp-Datei. Btw müssen Template-Implementationen in der kompilierenden Einheit bekannt sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1510819</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1510819</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Fri, 16 May 2008 23:04:45 GMT</pubDate></item><item><title><![CDATA[Reply to Änfängerproblem bei klassen-template on Fri, 16 May 2008 23:07:59 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &quot;Matrix.h&quot;
#include &lt;exception&gt;

Matrix::Matrix()
{

}

Matrix::~Matrix()
{
}

Matrix::Matrix(unsigned long min, unsigned long nin)
{
	m = min;
	n = nin;
	//matrix = new();//speicher für n*m elemente des typs ??? holen
}

Matrix Matrix::operator + (Matrix op2)
{
	//Matrizen müssen gleiche größe haben
	if(m == op2.m &amp;&amp; n == op2.n &amp;&amp; m != 0 &amp;&amp; n != 0)
	{
		Matrix tmp(m,n);
		for(unsigned long i = 0; i &lt; m*n; i++)
		{
			//MatTyp tmp.matrix[i] = MatTyp matrix[i] + MatTyp op2.matrix[i];//wie geht das?
		}
	}
	else if(m != op2.m)
	{
		throw(&quot;111 Fehler bei der Matrizenaddition: Zeilenanzahl ist nicht gleich&quot;);
	}
	else if(n != op2.n)
	{
		throw(&quot;112 Fehler bei der Matrizenaddition: Spaltenanzahl ist nicht gleich&quot;);
	}
	else if(m == 0 || n == 0)
	{
		throw(&quot;113 Fehler bei der Matrizenaddition: Matrix ist leer&quot;);
	}
	else
	{
		throw(&quot;110 Fehler bei der Matrizenaddition: Programmfehler in if-anweisung&quot;);
	}
	return op2;
}
</code></pre>
<p>hab eigentlich hier noch nicht viel gemacht weil ich erstma das mit dem template gebacken kriegen will</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1510821</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1510821</guid><dc:creator><![CDATA[stfischr]]></dc:creator><pubDate>Fri, 16 May 2008 23:07:59 GMT</pubDate></item><item><title><![CDATA[Reply to Änfängerproblem bei klassen-template on Fri, 16 May 2008 23:19:40 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template&lt;typename MatTyp&gt;
Matrix::Matrix()
{
}
usw
</code></pre>
<p>Irgendwie so <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>edit: <a href="http://www.cplusplus.com/doc/tutorial/templates.html" rel="nofollow">http://www.cplusplus.com/doc/tutorial/templates.html</a> und <a href="http://www.is.pku.edu.cn/~qzy/cpp/vc-stl/templates.htm" rel="nofollow">http://www.is.pku.edu.cn/~qzy/cpp/vc-stl/templates.htm</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1510826</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1510826</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Fri, 16 May 2008 23:19:40 GMT</pubDate></item><item><title><![CDATA[Reply to Änfängerproblem bei klassen-template on Fri, 16 May 2008 23:25:34 GMT]]></title><description><![CDATA[<p>hm hat auch net geholfen</p>
<p>aber ich werd wohl erstmal die tuts durchackern und mich morgen abend nochma melden</p>
<p>danke erstma soweit</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1510828</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1510828</guid><dc:creator><![CDATA[stfischr]]></dc:creator><pubDate>Fri, 16 May 2008 23:25:34 GMT</pubDate></item><item><title><![CDATA[Reply to Änfängerproblem bei klassen-template on Fri, 16 May 2008 23:37:02 GMT]]></title><description><![CDATA[<p>habs doch noch gebacken gekriegt</p>
<p>[cpp]template&lt;typename MatTyp&gt;<br />
Matrix**&lt;MatTyp&gt;**::Matrix()<br />
{<br />
}<br />
usw[/cpp]</p>
<p>hat gefehlt</p>
<p>vielen dank der zweite link hat mir sehr geholfen<br />
auch wenn ich erst herausfinden musste, dass <strong>&amp;lt</strong> == <strong>&lt;</strong> ist <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>jetzt komm ich erstma wieder alleine zurecht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1510831</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1510831</guid><dc:creator><![CDATA[stfischr]]></dc:creator><pubDate>Fri, 16 May 2008 23:37:02 GMT</pubDate></item></channel></rss>