<?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[Element dynamischer liste hinzufügen?]]></title><description><![CDATA[<p>Hi, ich wollte mal meine eingene Klasse erstellen, die wie ein simpler, dynamisher array funktioniert. Leider geht's schon zu begin schief: Ich kriege krumme werte in die liste, und ich hab' keinen schimmer warum. Wie mache ich also, dass ein element einfach hinzugefügt werden kann ?</p>
<pre><code class="language-cpp">template&lt;class T&gt; class LIST
{
public:
	LIST()
	{
		count = 0;
	}
	void operator &lt;&lt; (T elem)
	{
		count++;
		T* nlist = new T[count];
		if (!count)
			for (int i=0; i&lt;count-1; i++)
				nlist[i] = list[i];
		nlist[count] = elem;
		list = nlist;
	}
	T operator [] (int ix)
	{
		return list[ix];
	}
	int gsize() {return count};
private:
	int count;
	T* list;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/261536/element-dynamischer-liste-hinzufügen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 05:33:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/261536.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 19 Feb 2010 20:17:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Element dynamischer liste hinzufügen? on Fri, 19 Feb 2010 20:17:04 GMT]]></title><description><![CDATA[<p>Hi, ich wollte mal meine eingene Klasse erstellen, die wie ein simpler, dynamisher array funktioniert. Leider geht's schon zu begin schief: Ich kriege krumme werte in die liste, und ich hab' keinen schimmer warum. Wie mache ich also, dass ein element einfach hinzugefügt werden kann ?</p>
<pre><code class="language-cpp">template&lt;class T&gt; class LIST
{
public:
	LIST()
	{
		count = 0;
	}
	void operator &lt;&lt; (T elem)
	{
		count++;
		T* nlist = new T[count];
		if (!count)
			for (int i=0; i&lt;count-1; i++)
				nlist[i] = list[i];
		nlist[count] = elem;
		list = nlist;
	}
	T operator [] (int ix)
	{
		return list[ix];
	}
	int gsize() {return count};
private:
	int count;
	T* list;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1858401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1858401</guid><dc:creator><![CDATA[lk]]></dc:creator><pubDate>Fri, 19 Feb 2010 20:17:04 GMT</pubDate></item><item><title><![CDATA[Reply to Element dynamischer liste hinzufügen? on Fri, 19 Feb 2010 20:29:10 GMT]]></title><description><![CDATA[<p>Der Fehler ist bei &quot;if(!count)&quot; zu suchen.<br />
Du zählst den Zähler hoch, und kopierst das Array aber nur wenn count false ist also !=0!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1858407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1858407</guid><dc:creator><![CDATA[Andromedar]]></dc:creator><pubDate>Fri, 19 Feb 2010 20:29:10 GMT</pubDate></item><item><title><![CDATA[Reply to Element dynamischer liste hinzufügen? on Fri, 19 Feb 2010 20:31:51 GMT]]></title><description><![CDATA[<p>und was soll ich ändern ?<br />
Wenn ich das einfach weglasse kireg ich eine access violation <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title="=\"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1858409</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1858409</guid><dc:creator><![CDATA[lk]]></dc:creator><pubDate>Fri, 19 Feb 2010 20:31:51 GMT</pubDate></item><item><title><![CDATA[Reply to Element dynamischer liste hinzufügen? on Fri, 19 Feb 2010 20:41:48 GMT]]></title><description><![CDATA[<p>Ein weiteres Problem ist, dass du an index 0 nie nen Wert reinschreibst!<br />
Indize bei Arrays starten mit i=0. Beim ersten list &lt;&lt; wert zählst du count auf 1, dein Array ist noch nicht initialisiert, an index=0 existiert noch kein Wert. Wenn du nun das Array kopierst wird auf einen ungültigen Wert zugegriffen -&gt; access violation.<br />
SOlltest du Problem haben dir das vorzustellen, mal dir eine Skizze auf, wie dein Objekt aussschaut am Anfang, und nachdem du Werte hizufügst.</p>
<p>BTW: EIn Debugger sagt dir das. Schau dass du dich bald damit anfreundest, dass du bei jedem unerklärlichen Fehler nicht Stunden investieren und dann ins Forum posten musst <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1858412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1858412</guid><dc:creator><![CDATA[Andromedar]]></dc:creator><pubDate>Fri, 19 Feb 2010 20:41:48 GMT</pubDate></item></channel></rss>