<?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[templates]]></title><description><![CDATA[<p>erstmal mein code</p>
<pre><code>template&lt;int n,int m=n&gt;
class matrix
{
 public:
 float Dat[n][m];

 // Konstruktoren
 //---------------------------------------------------------------------------
 matrix()
	{
		if(n==m)
		for(int i=0;i&lt;n;i++)
			for(int t=0;t&lt;m;t++)
				{
					if(i==t)
						Dat[i][t]=1;
					else
						Dat[i][t]=0;
				}
	}
 //---------------------------------------------------------------------------
 //Debug Methoden
 #ifdef DEBUG
 //---------------------------------------------------------------------------
 void show()
	{
	for(int i=0;i&lt;n;i++)
	{
	for(int t=0;t&lt;m;t++)
		{
		std::cout&lt;&lt;Dat[i][t]&lt;&lt;&quot;\t&quot;;
		}
		std::cout&lt;&lt;std::endl;
		}

	}
 //---------------------------------------------------------------------------
 #endif

 //Operatoren
 //---------------------------------------------------------------------------
 matrix operator +(const matrix&lt;n,m&gt; &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]= this-&gt;Dat[i][t] + op.Dat[i][t];
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator -(const matrix&lt;n,m&gt; &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]= this-&gt;Dat[i][t] - op.Dat[i][t];
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator +(const float &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]=Dat[i][t] + op;
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator -(const float &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]=Dat[i][t] - op;
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator *(const float &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]=Dat[i][t] * op;
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator /(const float &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]=Dat[i][t] / op;
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator *(const matrix&lt;,n&gt; &amp;op)
	{

	}
};
</code></pre>
<p>Mein Problem ist der Operator am Schluss<br />
die Funktion soll 2 matrizen miteinander multiplizieren.<br />
bekannterweise muss dazu matrix2 so viele Spalten haben wie matrix1 zeilen<br />
n sind die zeilen und m die spalten in meinem template<br />
da aber n von matrix 2 irrelevant ist müsse ich es irgendwie hinbekommen als Parameter der Funktion eine Matrix mit beliebigem n anzugeben allerdings m als n von matrix1. Wie kann ich das in C++ schreiben.<br />
Ich hoffe das war halbwegsverständlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/169151/templates</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 15:51:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/169151.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 02 Jan 2007 15:35:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to templates on Tue, 02 Jan 2007 15:35:30 GMT]]></title><description><![CDATA[<p>erstmal mein code</p>
<pre><code>template&lt;int n,int m=n&gt;
class matrix
{
 public:
 float Dat[n][m];

 // Konstruktoren
 //---------------------------------------------------------------------------
 matrix()
	{
		if(n==m)
		for(int i=0;i&lt;n;i++)
			for(int t=0;t&lt;m;t++)
				{
					if(i==t)
						Dat[i][t]=1;
					else
						Dat[i][t]=0;
				}
	}
 //---------------------------------------------------------------------------
 //Debug Methoden
 #ifdef DEBUG
 //---------------------------------------------------------------------------
 void show()
	{
	for(int i=0;i&lt;n;i++)
	{
	for(int t=0;t&lt;m;t++)
		{
		std::cout&lt;&lt;Dat[i][t]&lt;&lt;&quot;\t&quot;;
		}
		std::cout&lt;&lt;std::endl;
		}

	}
 //---------------------------------------------------------------------------
 #endif

 //Operatoren
 //---------------------------------------------------------------------------
 matrix operator +(const matrix&lt;n,m&gt; &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]= this-&gt;Dat[i][t] + op.Dat[i][t];
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator -(const matrix&lt;n,m&gt; &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]= this-&gt;Dat[i][t] - op.Dat[i][t];
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator +(const float &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]=Dat[i][t] + op;
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator -(const float &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]=Dat[i][t] - op;
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator *(const float &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]=Dat[i][t] * op;
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator /(const float &amp;op)
	{
	matrix&lt;n,m&gt; erg;
	for(int i=0;i&lt;n;i++)
		for(int t=0;t&lt;m;t++)
			{
			erg.Dat[i][t]=Dat[i][t] / op;
			}
	return erg;
	}
 //---------------------------------------------------------------------------
 matrix operator *(const matrix&lt;,n&gt; &amp;op)
	{

	}
};
</code></pre>
<p>Mein Problem ist der Operator am Schluss<br />
die Funktion soll 2 matrizen miteinander multiplizieren.<br />
bekannterweise muss dazu matrix2 so viele Spalten haben wie matrix1 zeilen<br />
n sind die zeilen und m die spalten in meinem template<br />
da aber n von matrix 2 irrelevant ist müsse ich es irgendwie hinbekommen als Parameter der Funktion eine Matrix mit beliebigem n anzugeben allerdings m als n von matrix1. Wie kann ich das in C++ schreiben.<br />
Ich hoffe das war halbwegsverständlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1201232</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1201232</guid><dc:creator><![CDATA[walljumper]]></dc:creator><pubDate>Tue, 02 Jan 2007 15:35:30 GMT</pubDate></item><item><title><![CDATA[Reply to templates on Tue, 02 Jan 2007 16:01:24 GMT]]></title><description><![CDATA[<p>So sollte es gehen:</p>
<pre><code class="language-cpp">template&lt; int n, int m=n &gt;
class matrix
{
public:
    template&lt; int k &gt;
    matrix&lt; n, k &gt; operator*( const matrix&lt; m, k &gt;&amp; b )
    {
        matrix&lt; n, k &gt; erg;
        // erg berechnen
        return erg;
    }
private:
    float m_dat[n][m];
};

int main()
{
    matrix&lt; 2, 3 &gt; m23;
    matrix&lt; 3, 7 &gt; m37;
    matrix&lt; 2, 7 &gt; m27 = m23 * m37;
    return 0;
}
</code></pre>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1201255</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1201255</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Tue, 02 Jan 2007 16:01:24 GMT</pubDate></item><item><title><![CDATA[Reply to templates on Tue, 02 Jan 2007 16:13:50 GMT]]></title><description><![CDATA[<p>ja scheint zu gehe</p>
<p>thx</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1201263</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1201263</guid><dc:creator><![CDATA[walljumper]]></dc:creator><pubDate>Tue, 02 Jan 2007 16:13:50 GMT</pubDate></item></channel></rss>