<?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[Grundsätzliche Frage]]></title><description><![CDATA[<p>Ich habe mal eine Frage zu einer Klasse namens Matrix.<br />
Und zwar wollte ich sie etwa so aufbauen:</p>
<pre><code class="language-cpp">class Matrix
{
      private:
              const int DIMENSION;
              int matrix[DIMENSION][DIMENSION];
      public:
             Matrix(int D=3) : DIMENSION(D) {};
};
</code></pre>
<p>Ok. Dass das nicht so wirklich funktioniert kann ich mir denken.</p>
<p>Dann wollte ich etwas ähnliches machen. Nämlich dieses hier:</p>
<pre><code class="language-cpp">class Matrix
{
      private:
              const int DIMENSION;
              int *matrix[][];
      public:
             Matrix(int D=3) : DIMENSION(D)
             {
                        matrix = new int[DIMENSION][DIMENSION];
             };
};
</code></pre>
<p>Das geht aber auch nicht.</p>
<p>Also ich kann nicht erklären was ich genau will, aber ich denke das sieht man.<br />
Kann mir jemand einen Rat geben wie ich das vernünftig anstelle?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/236251/grundsätzliche-frage</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 01:24:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/236251.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 12 Mar 2009 18:13:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Grundsätzliche Frage on Thu, 12 Mar 2009 18:13:07 GMT]]></title><description><![CDATA[<p>Ich habe mal eine Frage zu einer Klasse namens Matrix.<br />
Und zwar wollte ich sie etwa so aufbauen:</p>
<pre><code class="language-cpp">class Matrix
{
      private:
              const int DIMENSION;
              int matrix[DIMENSION][DIMENSION];
      public:
             Matrix(int D=3) : DIMENSION(D) {};
};
</code></pre>
<p>Ok. Dass das nicht so wirklich funktioniert kann ich mir denken.</p>
<p>Dann wollte ich etwas ähnliches machen. Nämlich dieses hier:</p>
<pre><code class="language-cpp">class Matrix
{
      private:
              const int DIMENSION;
              int *matrix[][];
      public:
             Matrix(int D=3) : DIMENSION(D)
             {
                        matrix = new int[DIMENSION][DIMENSION];
             };
};
</code></pre>
<p>Das geht aber auch nicht.</p>
<p>Also ich kann nicht erklären was ich genau will, aber ich denke das sieht man.<br />
Kann mir jemand einen Rat geben wie ich das vernünftig anstelle?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678871</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678871</guid><dc:creator><![CDATA[Neuling09]]></dc:creator><pubDate>Thu, 12 Mar 2009 18:13:07 GMT</pubDate></item><item><title><![CDATA[Reply to Grundsätzliche Frage on Thu, 12 Mar 2009 18:25:46 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">//Das geht so nicht
int *matrix[][];
//korrekt wäre das hier
int *matrix;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1678873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678873</guid><dc:creator><![CDATA[Xebov]]></dc:creator><pubDate>Thu, 12 Mar 2009 18:25:46 GMT</pubDate></item><item><title><![CDATA[Reply to Grundsätzliche Frage on Thu, 12 Mar 2009 18:31:11 GMT]]></title><description><![CDATA[<p>Das hier geht aber auch nicht:</p>
<pre><code class="language-cpp">class Matrix
{
      private:
              const int DIMENSION;
              int *matrix;
      public:
             Matrix(int D=3) : DIMENSION(D)
             {
                        matrix = new int[DIMENSION][DIMENSION];
             };
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1678876</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678876</guid><dc:creator><![CDATA[Neuling09]]></dc:creator><pubDate>Thu, 12 Mar 2009 18:31:11 GMT</pubDate></item><item><title><![CDATA[Reply to Grundsätzliche Frage on Thu, 12 Mar 2009 18:39:19 GMT]]></title><description><![CDATA[<p>Neuling09 schrieb:</p>
<blockquote>
<p>Das geht aber auch nicht.</p>
</blockquote>
<p>Das ist schön und was genau geht nicht ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678880</guid><dc:creator><![CDATA[freaky]]></dc:creator><pubDate>Thu, 12 Mar 2009 18:39:19 GMT</pubDate></item><item><title><![CDATA[Reply to Grundsätzliche Frage on Thu, 12 Mar 2009 18:43:16 GMT]]></title><description><![CDATA[<p>FreakY&lt;3Cpp schrieb:</p>
<blockquote>
<p>Neuling09 schrieb:</p>
<blockquote>
<p>Das geht aber auch nicht.</p>
</blockquote>
<p>Das ist schön und was genau geht nicht ?</p>
</blockquote>
<blockquote>
<p>cannot convert 'Matrix[<em>][3]' to 'int</em>' in assignment</p>
</blockquote>
<p>Und ich weiß nicht wie ich das ändern soll damit es geht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678883</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678883</guid><dc:creator><![CDATA[Neuling09]]></dc:creator><pubDate>Thu, 12 Mar 2009 18:43:16 GMT</pubDate></item><item><title><![CDATA[Reply to Grundsätzliche Frage on Thu, 12 Mar 2009 18:49:31 GMT]]></title><description><![CDATA[<p>Kleiner Tip.Benutze die std Container, wie std::vector&lt;T&gt; und verschachtele den einfach wie hier:<br />
`</p>
<p>std::vector&lt;std::vector&lt;T&gt; &gt;;`<br />
Ist auch ein 2-Dimensionales Array.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678891</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Thu, 12 Mar 2009 18:49:31 GMT</pubDate></item><item><title><![CDATA[Reply to Grundsätzliche Frage on Thu, 12 Mar 2009 19:03:18 GMT]]></title><description><![CDATA[<p>Wenn die Dimensionen in x und y Richtung nicht variabel sind, dann empfiehlt es sich sowieso, nicht ein 2D Array oder ähnliches zu nehmen. Man kommt deutlich einfacher zu recht, wenn man die Sache auf ein 1D Array abbildet:</p>
<p>Ohne C++ Standardbibliothek:</p>
<pre><code class="language-cpp">class Matrix
{
private:
  int m_dim;
  int* m_matrix;

public:
  Matrix(int dim)
    : m_dim(dim)
    , m_matrix(0)
  {
    m_matrix = new int[dim * dim];
  }

  ~Matrix()
  {
    delete[] m_matrix;
  }

public:
  int&amp; get(int x, int y)
  {
    int index = y * m_dim + x;

    assert(index &gt;= 0 &amp;&amp; index &lt; (m_dim * m_dim));

    return m_matrix[index];
  }

  // usw.
}
</code></pre>
<p>Mit der Standardbibliothek:</p>
<pre><code class="language-cpp">private:
  int m_dim;
  std::vector&lt;int&gt; m_matrix;

public:
  Matrix(int dim)
    : m_dim(dim)
    , m_matrix(dim * dim)
  {
  }

public:
  int&amp; get(int x, int y)
  {
    return m_matrix[y * m_dim + x];
    // Assert passiert hier automatisch.
    // Bei den meistens Standardbibliotheken, zumindest.
  }

  // usw.
}
</code></pre>
<p><a href="http://www.cplusplus.com/reference/" rel="nofollow">http://www.cplusplus.com/reference/</a></p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678899</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Thu, 12 Mar 2009 19:03:18 GMT</pubDate></item><item><title><![CDATA[Reply to Grundsätzliche Frage on Thu, 12 Mar 2009 19:17:33 GMT]]></title><description><![CDATA[<p>Danke für die Antworten.</p>
<p>So ähnlich wie du, davere, hatte ich das auch mal gelöst.<br />
Das sah dann so aus:</p>
<pre><code class="language-cpp">Matrix::Matrix(int d)
{               
                DIMENSION = d;
                matrix = (int *) malloc(DIMENSION*DIMENSION*sizeof(int));
                for (int i=0; i&lt;DIMENSION; i++)
                    for (int j=0; j&lt;DIMENSION; j++)
                        if (i == j) *(matrix+(i*DIMENSION+j)) = 1;
                           else *(matrix+(i*DIMENSION+j)) = 0;
};
</code></pre>
<p>Weiß nicht ob das so schön ist in C++.</p>
<p>Ich wollte es darum mit einem 2D Array versuchen und ich dachte in C++ würde das so vielleicht gehen. Naja schade. Trotzdem danke für die Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678905</guid><dc:creator><![CDATA[Neuling09]]></dc:creator><pubDate>Thu, 12 Mar 2009 19:17:33 GMT</pubDate></item></channel></rss>