<?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[Arrays von Pointer dynamisch erzeugen]]></title><description><![CDATA[<p>Hi Leuts, ich hab ein Problem mit dem dynamischen Erzeugen von Pointerarrays deren Größe erst zur Laufzeit feststeht.<br />
Bisher benutze ich folgenden Code, der auch einwandfrei funktioniert:</p>
<pre><code class="language-cpp">void MyClass::ExportGridToXml(wxString strFile)
{
	TiXmlDocument doc;
	int n = m_grid1-&gt;GetNumberRows();
	TiXmlElement *XmlMainNode;
	TiXmlElement* DataSet[40];
	TiXmlElement* Data[40][5];
	TiXmlText* XmlTxt[40][5];
	int i,j;
	wxString str;

	TiXmlDeclaration * decl = new TiXmlDeclaration( &quot;1.0&quot;, &quot;&quot;, &quot;&quot; );
	XmlMainNode = new TiXmlElement(&quot;Batterieladeprotokoll&quot;);

	for (i=0;i&lt;n;i++)
	{
		Data[i][0] = new TiXmlElement(&quot;A&quot;);
		Data[i][1] = new TiXmlElement(&quot;B&quot;);
		Data[i][2] = new TiXmlElement(&quot;C&quot;);
		Data[i][3] = new TiXmlElement(&quot;D&quot;);
		Data[i][4] = new TiXmlElement(&quot;E&quot;);

		for (j=0;j&lt;5;j++)
		{
			str = m_grid1-&gt;GetCellValue(i,j);
			XmlTxt[i][j+1] = new TiXmlText(str);
			Data[i][j+1]-&gt;LinkEndChild(XmlTxt[i][j+1]);
			DataSet[i]-&gt;LinkEndChild(Data[i][j+1]);
		}
		XmlMainNode-&gt;LinkEndChild(DataSet[i]);
	}
	doc.LinkEndChild( decl );
	doc.LinkEndChild(XmlMainNode);
	doc.SaveFile(strFile);
}
</code></pre>
<p>Nun habe ich das Problem, das die 40 sich ändert, d.h. die Arraygröße ändert sich zur Laufzeit. Den Ausdruck</p>
<pre><code class="language-cpp">TiXmlElement* DataSet[40];
</code></pre>
<p>durch</p>
<pre><code class="language-cpp">TiXmlElement**DataSet = new TiXmlElement*[n];
</code></pre>
<p>kriege ich ja noch gebacken. Problematischer wirds bei den Variablen Data und XmlText, obwohl die 5 konstant bleibt. Kann mir jemand helfen ? Danke....</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/262696/arrays-von-pointer-dynamisch-erzeugen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 11:13:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/262696.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 10 Mar 2010 08:08:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Arrays von Pointer dynamisch erzeugen on Wed, 10 Mar 2010 08:08:05 GMT]]></title><description><![CDATA[<p>Hi Leuts, ich hab ein Problem mit dem dynamischen Erzeugen von Pointerarrays deren Größe erst zur Laufzeit feststeht.<br />
Bisher benutze ich folgenden Code, der auch einwandfrei funktioniert:</p>
<pre><code class="language-cpp">void MyClass::ExportGridToXml(wxString strFile)
{
	TiXmlDocument doc;
	int n = m_grid1-&gt;GetNumberRows();
	TiXmlElement *XmlMainNode;
	TiXmlElement* DataSet[40];
	TiXmlElement* Data[40][5];
	TiXmlText* XmlTxt[40][5];
	int i,j;
	wxString str;

	TiXmlDeclaration * decl = new TiXmlDeclaration( &quot;1.0&quot;, &quot;&quot;, &quot;&quot; );
	XmlMainNode = new TiXmlElement(&quot;Batterieladeprotokoll&quot;);

	for (i=0;i&lt;n;i++)
	{
		Data[i][0] = new TiXmlElement(&quot;A&quot;);
		Data[i][1] = new TiXmlElement(&quot;B&quot;);
		Data[i][2] = new TiXmlElement(&quot;C&quot;);
		Data[i][3] = new TiXmlElement(&quot;D&quot;);
		Data[i][4] = new TiXmlElement(&quot;E&quot;);

		for (j=0;j&lt;5;j++)
		{
			str = m_grid1-&gt;GetCellValue(i,j);
			XmlTxt[i][j+1] = new TiXmlText(str);
			Data[i][j+1]-&gt;LinkEndChild(XmlTxt[i][j+1]);
			DataSet[i]-&gt;LinkEndChild(Data[i][j+1]);
		}
		XmlMainNode-&gt;LinkEndChild(DataSet[i]);
	}
	doc.LinkEndChild( decl );
	doc.LinkEndChild(XmlMainNode);
	doc.SaveFile(strFile);
}
</code></pre>
<p>Nun habe ich das Problem, das die 40 sich ändert, d.h. die Arraygröße ändert sich zur Laufzeit. Den Ausdruck</p>
<pre><code class="language-cpp">TiXmlElement* DataSet[40];
</code></pre>
<p>durch</p>
<pre><code class="language-cpp">TiXmlElement**DataSet = new TiXmlElement*[n];
</code></pre>
<p>kriege ich ja noch gebacken. Problematischer wirds bei den Variablen Data und XmlText, obwohl die 5 konstant bleibt. Kann mir jemand helfen ? Danke....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1866813</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866813</guid><dc:creator><![CDATA[Thule]]></dc:creator><pubDate>Wed, 10 Mar 2010 08:08:05 GMT</pubDate></item><item><title><![CDATA[Reply to Arrays von Pointer dynamisch erzeugen on Wed, 10 Mar 2010 09:45:59 GMT]]></title><description><![CDATA[<p>Ganz einfach: Nimm std::vector. Alle Probleme gelöst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1866869</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866869</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 10 Mar 2010 09:45:59 GMT</pubDate></item><item><title><![CDATA[Reply to Arrays von Pointer dynamisch erzeugen on Wed, 10 Mar 2010 10:30:28 GMT]]></title><description><![CDATA[<p>Habe ich noch nie benutzt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /> Aber hört sich interessant an, mal ein wenig einlesen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1866901</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866901</guid><dc:creator><![CDATA[Thule]]></dc:creator><pubDate>Wed, 10 Mar 2010 10:30:28 GMT</pubDate></item><item><title><![CDATA[Reply to Arrays von Pointer dynamisch erzeugen on Wed, 10 Mar 2010 11:35:09 GMT]]></title><description><![CDATA[<p>Anyway, eine Lösung habe ich, ich Blödfön <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /><br />
Da die Strukturen ja direkt verlinkt werden, kann ich die Zeiger nach dem Verlinken direkt mit neuen Strukturen überschreiben :-))) Wieso also die ganzen Arrays überhaupt ? Geht mit einfachen Pointern viel einfacher......<br />
Trotzdem Danke für den Hinweis .........</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1866936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866936</guid><dc:creator><![CDATA[Thule]]></dc:creator><pubDate>Wed, 10 Mar 2010 11:35:09 GMT</pubDate></item></channel></rss>