<?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[dynamisches zweidimensionals array]]></title><description><![CDATA[<p>Mit folgenden Code erzeuge ich ein zweidimensionales Array. Dabei ist Max_S einen Konstante und AnzahlZeilen eine Variable. Ich möchte aber dieses Array mit zwei Variablen AnzahlZeilen und AnzahlSpalten erzeugen. Wenn ich Max_S durch die Variable AnzahlSpalten ersetze, erhalte ich lauter Fehlermeldungen.<br />
Ich benutze Visual C++6 und schreibe eine Win32-Konsolenanwendung.</p>
<p>double (*testarray) [Max_S] = new double [AnzahlZeilen][Max_S];<br />
delete [] testarray;</p>
<p>Vielen Dank für die Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/6203/dynamisches-zweidimensionals-array</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 23:24:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/6203.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 15 Jun 2003 19:35:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to dynamisches zweidimensionals array on Sun, 15 Jun 2003 19:35:00 GMT]]></title><description><![CDATA[<p>Mit folgenden Code erzeuge ich ein zweidimensionales Array. Dabei ist Max_S einen Konstante und AnzahlZeilen eine Variable. Ich möchte aber dieses Array mit zwei Variablen AnzahlZeilen und AnzahlSpalten erzeugen. Wenn ich Max_S durch die Variable AnzahlSpalten ersetze, erhalte ich lauter Fehlermeldungen.<br />
Ich benutze Visual C++6 und schreibe eine Win32-Konsolenanwendung.</p>
<p>double (*testarray) [Max_S] = new double [AnzahlZeilen][Max_S];<br />
delete [] testarray;</p>
<p>Vielen Dank für die Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/30100</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/30100</guid><dc:creator><![CDATA[ross]]></dc:creator><pubDate>Sun, 15 Jun 2003 19:35:00 GMT</pubDate></item><item><title><![CDATA[Reply to dynamisches zweidimensionals array on Sun, 15 Jun 2003 19:49:00 GMT]]></title><description><![CDATA[<p>mit double (*testarray) [Max_S], erzeugst du ja einen Array. Du musst in C wenn du einen Array erzeugst beim compilieren festlegen, wie groß dieser ist. Darum nimmt er zwar die Konstante, aber keine Variable. Du musst einen Zeiger erstellen und diesem dann einen Zeigerarray zuweisen.</p>
<pre><code class="language-cpp">int xSize;
    int ySize;
    double** tArray = NULL;
    tArray = new double*[xSize];
    // jetzt jedem Element einen zuweisen!!
    for (int i=0;i&lt;xSize;i++) tArray[i] = new double[ySize];
</code></pre>
<p>habs jetzt nicht getestet aber so ungefähr müsste das funktioneren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/30101</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/30101</guid><dc:creator><![CDATA[GeorgeHomes]]></dc:creator><pubDate>Sun, 15 Jun 2003 19:49:00 GMT</pubDate></item><item><title><![CDATA[Reply to dynamisches zweidimensionals array on Mon, 16 Jun 2003 06:30:00 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/2752">@GeorgeHomes</a><br />
Wollen wir hier nicht die MFC verwenden?</p>
<pre><code class="language-cpp">typedef CArray&lt;double&gt; arDouble;
CArray&lt;arDouble&gt; ar_in_X;
ar_in_X.SetSize( AnzahlSpalten);
for( int i=0; i&lt;ar.GetCount(); i++)
  ar_in_X[i].SetSize( AnzahlZeilen);
// ab hier kannst Du in gewohnter [][]-Schreibweise auf die Elemente zugreifen
// delete[] ...; ist NICHT notwendig
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/30102</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/30102</guid><dc:creator><![CDATA[RenéG]]></dc:creator><pubDate>Mon, 16 Jun 2003 06:30:00 GMT</pubDate></item><item><title><![CDATA[Reply to dynamisches zweidimensionals array on Mon, 16 Jun 2003 06:49:00 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/638">@RenéG</a>: Dann musst du aber auch die einzelnen Arrays irgendwie miteinander synchronisieren oder auf einer statischen Größe halten. Sonst könnte es ja (wenn man nicht aufpasst) passieren, dass z.B. Spalte 1 mehr Zeilen hat als Spalte 2. Ich würde das ganze in eine eigene Klasse einbinden.</p>
<pre><code class="language-cpp">template&lt;class TYPE, class ARG_TYPE&gt;
class CMatrix : public CArray&lt;class TYPE, class ARG_TYPE&gt;
{
  CMatrix(const int cx, const int cy) {
    SetSize(cx);
    for(int i = 0; i &lt; cx; ++i)
      GetAt(i).SetSize(cy);
  }
  virtual ~CMatrix() {}

  ARG_TYPE GetAt(const int x, const int y)
  {
    // Hier eventuell noch abprüfen, ob zugegriffen werden darf
    return GetAt(x)[y];
  }
  void SetAt(const int x, const int y, ARG_TYPE t)
  {
    // Hier eventuell noch abprüfen, ob zugegriffen werden darf
    return GetAt(x).SetAt(y, t);
  }
};
</code></pre>
<p>Naja, so in der Art irgendwie!</p>
<p>[ Dieser Beitrag wurde am 16.06.2003 um 08:50 Uhr von <strong>MaSTaH</strong> editiert. ]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/30103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/30103</guid><dc:creator><![CDATA[Walli]]></dc:creator><pubDate>Mon, 16 Jun 2003 06:49:00 GMT</pubDate></item><item><title><![CDATA[Reply to dynamisches zweidimensionals array on Mon, 16 Jun 2003 08:03:00 GMT]]></title><description><![CDATA[<p>Ich möchte lieber die Version von GeorgeHomes (also keine MFC) verwenden.</p>
<p>Wie gebe ich dann das Array wieder frei?</p>
<p>Vielleicht so: delete [] tArray;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/30104</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/30104</guid><dc:creator><![CDATA[ross]]></dc:creator><pubDate>Mon, 16 Jun 2003 08:03:00 GMT</pubDate></item><item><title><![CDATA[Reply to dynamisches zweidimensionals array on Mon, 16 Jun 2003 08:24:00 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/3537">@ross</a></p>
<p>Wieso postest Du dann erst bei MFC, wenn Du sie gar nicht verwenden willst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/30105</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/30105</guid><dc:creator><![CDATA[RenéG]]></dc:creator><pubDate>Mon, 16 Jun 2003 08:24:00 GMT</pubDate></item><item><title><![CDATA[Reply to dynamisches zweidimensionals array on Mon, 16 Jun 2003 08:45:00 GMT]]></title><description><![CDATA[<blockquote>
<p>Original erstellt von &lt;ross&gt;:<br />
<strong>Wie gebe ich dann das Array wieder frei?</strong></p>
</blockquote>
<p>Genau anders herum wie du es aufgebaut hast...</p>
<pre><code class="language-cpp">for(int i=0;i&lt;xSize;++i)
      delete[] tArray[i];
    delete[] tArray;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/30106</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/30106</guid><dc:creator><![CDATA[Walli]]></dc:creator><pubDate>Mon, 16 Jun 2003 08:45:00 GMT</pubDate></item><item><title><![CDATA[Reply to dynamisches zweidimensionals array on Mon, 16 Jun 2003 19:49:00 GMT]]></title><description><![CDATA[<p>@ReneG<br />
Hast ja recht. Eigentlich ja dämlich das Rad neu zu erfinden, wenn man eh schon mit einer Kapselung wie der MFC Arbeitet. Ich bin halt der typische &quot;Low-Level&quot; Mensch. Irgendwie macht es mir einen tierischen spaß, das Rad neu zu erfinden;).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/30107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/30107</guid><dc:creator><![CDATA[GeorgeHomes]]></dc:creator><pubDate>Mon, 16 Jun 2003 19:49:00 GMT</pubDate></item></channel></rss>