<?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[Matrixklasse -- operator[]]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich schreibe im Moment an einer Matrixklasse. Ich will es irgentwie einrichten, dass ich mit Matrix[line][column] auf ein einzelnes Element der Matrix zugreifen kann. Wie kann ich das machen, bzw. welchen Operator muss ich dafür überschreiben?</p>
<p>Mfg cpt.hawk</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/228732/matrixklasse-operator</link><generator>RSS for Node</generator><lastBuildDate>Thu, 02 Jul 2026 18:23:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/228732.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 02 Dec 2008 10:43:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Matrixklasse -- operator[] on Tue, 02 Dec 2008 10:43:27 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich schreibe im Moment an einer Matrixklasse. Ich will es irgentwie einrichten, dass ich mit Matrix[line][column] auf ein einzelnes Element der Matrix zugreifen kann. Wie kann ich das machen, bzw. welchen Operator muss ich dafür überschreiben?</p>
<p>Mfg cpt.hawk</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1624204</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1624204</guid><dc:creator><![CDATA[cpt.hawk]]></dc:creator><pubDate>Tue, 02 Dec 2008 10:43:27 GMT</pubDate></item><item><title><![CDATA[Reply to Matrixklasse -- operator[] on Tue, 02 Dec 2008 10:50:25 GMT]]></title><description><![CDATA[<p>Den normalen operator[size_t idx], wuerd ich vermuten. Der muss dann halt was zurueckliefern, das wieder indizierbar ist, z. B. ein Array oder einen Vector oder einen Proxy auf deine interne Datenstruktur.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1624210</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1624210</guid><dc:creator><![CDATA[Blue-Tiger]]></dc:creator><pubDate>Tue, 02 Dec 2008 10:50:25 GMT</pubDate></item><item><title><![CDATA[Reply to Matrixklasse -- operator[] on Tue, 02 Dec 2008 12:51:31 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

template&lt;typename T,size_t SIZEY,size_t SIZEX&gt;
class Matrix
{
    private:
    T data[SIZEY][SIZEX];
    public:
    struct AccessProxy
    {
        Matrix* m;
        size_t y;
        AccessProxy(Matrix *m,size_t y)
        :m(m),y(y)
        {
        }
        T&amp; operator[](size_t x)
        {
            return m-&gt;data[y][x];
        }
    };
    AccessProxy operator[](size_t y)
    {
        return AccessProxy(this,y);
    }
};

int main()
{
    Matrix&lt;int,3,4&gt; m;
    for(int y=0;y!=3;++y)
        for(int x=0;x&lt;=4;++x)
            m[y][x]=x*y;
    for(int y=0;y!=3;++y)
    {
        for(int x=0;x&lt;=4;++x)
            cout&lt;&lt;m[y][x]&lt;&lt;'\t';
        cout&lt;&lt;'\n';
    }
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1624282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1624282</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 02 Dec 2008 12:51:31 GMT</pubDate></item><item><title><![CDATA[Reply to Matrixklasse -- operator[] on Tue, 09 Dec 2008 14:39:50 GMT]]></title><description><![CDATA[<p>Danke für die Hilfe. Ich habs aber jetzt anders gelöst und zwar mit dem ()-operator.</p>
<p>Jetzt aber eine andere Frage:</p>
<p>Ich krieg nen Fehler, den ich mir nicht erklären kann.</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
class Matrix{

	private:
	int l;
	int c;
	T **matrix;

	public:
	Matrix(int lines = 5, int columns = 5);
	Matrix(const Matrix&lt;T&gt;&amp; m);
	~Matrix();

	Matrix&lt;T&gt;&amp; operator=(const Matrix&lt;T&gt;&amp; m);
	Matrix&lt;T&gt;&amp; operator+=(const Matrix&lt;T&gt;&amp; m);
	Matrix&lt;T&gt;&amp; operator-=(const Matrix&lt;T&gt;&amp; m);
	Matrix&lt;T&gt;&amp; operator*=(const Matrix&lt;T&gt;&amp; m);
	Matrix&lt;T&gt;&amp; operator/=(const Matrix&lt;T&gt;&amp; m);
	Matrix&lt;T&gt;&amp; inverse();

	int&amp; operator()(int line, int column);
	int&amp; operator()(int line, int column) const;

	int getLines() const;
	int getColumns() const;

	private:
	void init(int lines, int columns, T **m);
	void del() const;
};
/****************************************************************************/
// Gloable Funktionen
template&lt;typename T&gt;
Matrix&lt;T&gt;&amp; operator+(const Matrix&lt;T&gt;&amp; l, const Matrix&lt;T&gt;&amp; r);
template&lt;typename T&gt;
Matrix&lt;T&gt;&amp; operator-(const Matrix&lt;T&gt;&amp; l, const Matrix&lt;T&gt;&amp; r);
template&lt;typename T&gt;
Matrix&lt;T&gt;&amp; operator*(const Matrix&lt;T&gt;&amp; l, const Matrix&lt;T&gt;&amp; r);
template&lt;typename T&gt;
Matrix&lt;T&gt;&amp; operator/(const Matrix&lt;T&gt;&amp; l, const Matrix&lt;T&gt;&amp; r);
template&lt;typename T&gt;
ostream&amp; operator&lt;&lt;(ostream&amp; o, const Matrix&lt;T&gt;&amp; m);
/****************************************************************************/
</code></pre>
<blockquote>
<p>matrix.h:42: error: expected constructor, destructor, or type conversion before '&amp;' token</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1627657</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1627657</guid><dc:creator><![CDATA[cpt.hawk]]></dc:creator><pubDate>Tue, 09 Dec 2008 14:39:50 GMT</pubDate></item><item><title><![CDATA[Reply to Matrixklasse -- operator[] on Tue, 09 Dec 2008 14:45:13 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">std::ostream
</code></pre>
<p>??<br />
Oder hast du using namespace im Header drinne(Was man eigentlich nicht haben sollte)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1627663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1627663</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Tue, 09 Dec 2008 14:45:13 GMT</pubDate></item><item><title><![CDATA[Reply to Matrixklasse -- operator[] on Tue, 09 Dec 2008 14:47:21 GMT]]></title><description><![CDATA[<p>Ja, danke das wars.... war klar, dass es so ein scheiß sein muss.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1627665</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1627665</guid><dc:creator><![CDATA[cpt.hawk]]></dc:creator><pubDate>Tue, 09 Dec 2008 14:47:21 GMT</pubDate></item><item><title><![CDATA[Reply to Matrixklasse -- operator[] on Tue, 09 Dec 2008 14:50:16 GMT]]></title><description><![CDATA[<p>Schliesse mich Firefighter an, wenn denn die Zeile im Fehlercode mit der Zeile im gezeigten Code übereinstimmt.</p>
<p>Ansonsten noch eine Frage zu deinen Operatoren <code>+ - * /</code> . Wie kommt es, dass du dort eine Referenz zurück gibst? Diese Operatoren erstellen ein neues Objekt, eine Rückgabe einer Referenz wäre daher nur auf ein temporäres Objekt möglich. Was somit ganz sicher zu Fehler führen wird! Gib dort eine Kopie zurück.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1627667</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1627667</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Tue, 09 Dec 2008 14:50:16 GMT</pubDate></item><item><title><![CDATA[Reply to Matrixklasse -- operator[] on Tue, 09 Dec 2008 15:27:14 GMT]]></title><description><![CDATA[<p>danke für den tipp .... du hast recht das macht keinen sinn</p>
<p>ich hätts wahrscheinlich beim testen gemerkt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1627694</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1627694</guid><dc:creator><![CDATA[cpt.hawk]]></dc:creator><pubDate>Tue, 09 Dec 2008 15:27:14 GMT</pubDate></item><item><title><![CDATA[Reply to Matrixklasse -- operator[] on Wed, 10 Dec 2008 13:08:26 GMT]]></title><description><![CDATA[<blockquote>
<pre><code class="language-cpp">int&amp; operator()(int line, int column); 
    int&amp; operator()(int line, int column) const;
</code></pre>
</blockquote>
<p>Kann so aber nicht ganz stimmen... Vll eher so:</p>
<pre><code class="language-cpp">int&amp; operator()(int line, int column); 
    int operator()(int line, int column) const;
</code></pre>
<p>?<br />
Normalerweise gibt man bei der const Variante ne const-ref zurück, aber bei nem int... ^^</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1628228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1628228</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Wed, 10 Dec 2008 13:08:26 GMT</pubDate></item></channel></rss>