<?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[[C++] Array problem]]></title><description><![CDATA[<p>Eigentlich wollte ich euch folgendes fragen:</p>
<blockquote>
<p>Ich versuche in dieser Funktion ein Array um einen Eintrag zu erweitern.<br />
Funktioniert aber leider nicht so ganz, wie ich es mir erhofft hab.</p>
<p>Anscheinend funktioniert der Teil mit dem Kopieren nicht Richtig.</p>
</blockquote>
<p>Aber da ich bemerkt habe, das die deletes ( mit -&gt; markiert ) die Fehlerquelle waren, würde ich nun gern Folgendes wissen:</p>
<p>Wo platziere ich die deletes am Besten/Sinnvollsten ?<br />
Oder, wie lösche ich einzelne Indizies eines Arrays ?<br />
Oder, wie verwende ich die delete Funktion richtig ?</p>
<pre><code class="language-cpp">int c_sprite::addFrame ( char *bitmapPath )
{
	c_bitmap bitmap;

	if ( !bitmap.loadBitmap ( bitmapPath ) )
	{
		return false;
	}

	long pixels								= bitmap.bitmapData.infoheader.bitmapWidth * bitmap.bitmapData.infoheader.bitmapHeight;
	int newSize								= spriteData.header.spriteFrames + 1;

	// Temporäre Framedaten Initialisieren und Kopieren.

	spriteData.temp							= new struct c_sprite::d_sprite::d_frame[newSize];

	// Ist ein Frame Vorhanden ? Nein ? Dann eins hinzufügen. Ansonsten Kopieren.
	if ( spriteData.header.spriteFrames == 0 )
	{
		spriteData.temp[0].frameType		= SINGLEFRAME;
		spriteData.temp[0].frameOriginX		= NULL;
		spriteData.temp[0].frameOriginY		= NULL;
		spriteData.temp[0].frameWidth		= bitmap.bitmapData.infoheader.bitmapWidth;
		spriteData.temp[0].frameHeight		= bitmap.bitmapData.infoheader.bitmapHeight;

		int z = spriteData.temp[0].frameWidth * spriteData.temp[0].frameHeight;

		spriteData.temp[0].p_frameData = new unsigned char[z];

		for ( int d = 0; d &lt; z; d++ )
		{
			spriteData.temp[0].p_frameData[d]	= bitmap.bitmapData.p_pixelmap[d].pixel8Bit;
		}

		// Ist das neue Frame größer als die Angabe im Header ? Ja, dann Header Updaten.
		if ( spriteData.header.spriteWidth &lt; bitmap.bitmapData.infoheader.bitmapWidth )
			spriteData.header.spriteWidth = bitmap.bitmapData.infoheader.bitmapWidth;
		if ( spriteData.header.spriteHeight &lt; bitmap.bitmapData.infoheader.bitmapHeight )
			spriteData.header.spriteHeight = bitmap.bitmapData.infoheader.bitmapHeight;
		// Frameanzahl im Header Updaten.

		spriteData.header.spriteFrames ++;
	}

	else
	{
		for ( int f = 0; f &lt; spriteData.header.spriteFrames; f++ )
		{
			if ( spriteData.frame[f].frameType == SINGLEFRAME )
			{
				spriteData.temp[f].frameType		= spriteData.frame[f].frameType;
				spriteData.temp[f].frameOriginX		= spriteData.frame[f].frameOriginX;
				spriteData.temp[f].frameOriginY		= spriteData.frame[f].frameOriginY;
				spriteData.temp[f].frameWidth		= spriteData.frame[f].frameWidth;
				spriteData.temp[f].frameHeight		= spriteData.frame[f].frameHeight;

				int z = spriteData.temp[f].frameWidth * spriteData.temp[f].frameHeight;

				spriteData.temp[f].p_frameData = new unsigned char[z];

				for ( int d = 0; d &lt; z; d++ )
				{
					spriteData.temp[f].p_frameData[d]	= spriteData.frame[f].p_frameData[d];
				}

				// Altes FrAy löschen.

// -&gt;				delete [f] spriteData.frame;
			}
			else if ( spriteData.frame[f].frameType == GROUPFRAME )
			{
				return -1;
			}
		}
		// Neues Frame hinzufügen
		spriteData.temp[newSize-1].frameType		= SINGLEFRAME;
		spriteData.temp[newSize-1].frameOriginX		= NULL;
		spriteData.temp[newSize-1].frameOriginY		= NULL;
		spriteData.temp[newSize-1].frameWidth		= bitmap.bitmapData.infoheader.bitmapWidth;
		spriteData.temp[newSize-1].frameHeight		= bitmap.bitmapData.infoheader.bitmapHeight;

		int z = bitmap.bitmapData.infoheader.bitmapWidth * bitmap.bitmapData.infoheader.bitmapHeight;

		spriteData.temp[newSize-1].p_frameData = new unsigned char[z];

		for ( int d = 0; d &lt; z; d++ )
		{
			spriteData.temp[newSize-1].p_frameData[d]	= bitmap.bitmapData.p_pixelmap[d].pixel8Bit;
		}

		// Ist das neue Frame größer als die Angabe im Header ? Ja, dann Header Updaten.
		if ( spriteData.header.spriteWidth &lt; bitmap.bitmapData.infoheader.bitmapWidth )
			spriteData.header.spriteWidth = bitmap.bitmapData.infoheader.bitmapWidth;
		if ( spriteData.header.spriteHeight &lt; bitmap.bitmapData.infoheader.bitmapHeight )
			spriteData.header.spriteHeight = bitmap.bitmapData.infoheader.bitmapHeight;
		// Frameanzahl im Header Updaten.

		spriteData.header.spriteFrames ++;
	}

	// Neues FrameArray beantragen und Temporäre Daten hineinkopieren.

	spriteData.frame = new struct c_sprite::d_sprite::d_frame[spriteData.header.spriteFrames];

	for ( int f = 0; f &lt; spriteData.header.spriteFrames; f++ )
	{
		spriteData.frame[f].frameType			= spriteData.temp[f].frameType;
		spriteData.frame[f].frameOriginX		= spriteData.temp[f].frameOriginX;
		spriteData.frame[f].frameOriginY		= spriteData.temp[f].frameOriginY;
		spriteData.frame[f].frameWidth			= spriteData.temp[f].frameWidth;
		spriteData.frame[f].frameHeight			= spriteData.temp[f].frameHeight;

		int z = spriteData.frame[f].frameWidth * spriteData.frame[f].frameHeight;

		spriteData.frame[f].p_frameData = new unsigned char[z];

		for ( int d = 0; d &lt; z; d++ )
		{
			spriteData.frame[f].p_frameData[d]	= spriteData.temp[f].p_frameData[d];
		}
		// Temporäres Fray löschen.

// -&gt;		delete [f] spriteData.temp;
	}

	return true;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/181283/c-array-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 05:23:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/181283.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 12 May 2007 00:55:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [C++] Array problem on Sat, 12 May 2007 00:57:29 GMT]]></title><description><![CDATA[<p>Eigentlich wollte ich euch folgendes fragen:</p>
<blockquote>
<p>Ich versuche in dieser Funktion ein Array um einen Eintrag zu erweitern.<br />
Funktioniert aber leider nicht so ganz, wie ich es mir erhofft hab.</p>
<p>Anscheinend funktioniert der Teil mit dem Kopieren nicht Richtig.</p>
</blockquote>
<p>Aber da ich bemerkt habe, das die deletes ( mit -&gt; markiert ) die Fehlerquelle waren, würde ich nun gern Folgendes wissen:</p>
<p>Wo platziere ich die deletes am Besten/Sinnvollsten ?<br />
Oder, wie lösche ich einzelne Indizies eines Arrays ?<br />
Oder, wie verwende ich die delete Funktion richtig ?</p>
<pre><code class="language-cpp">int c_sprite::addFrame ( char *bitmapPath )
{
	c_bitmap bitmap;

	if ( !bitmap.loadBitmap ( bitmapPath ) )
	{
		return false;
	}

	long pixels								= bitmap.bitmapData.infoheader.bitmapWidth * bitmap.bitmapData.infoheader.bitmapHeight;
	int newSize								= spriteData.header.spriteFrames + 1;

	// Temporäre Framedaten Initialisieren und Kopieren.

	spriteData.temp							= new struct c_sprite::d_sprite::d_frame[newSize];

	// Ist ein Frame Vorhanden ? Nein ? Dann eins hinzufügen. Ansonsten Kopieren.
	if ( spriteData.header.spriteFrames == 0 )
	{
		spriteData.temp[0].frameType		= SINGLEFRAME;
		spriteData.temp[0].frameOriginX		= NULL;
		spriteData.temp[0].frameOriginY		= NULL;
		spriteData.temp[0].frameWidth		= bitmap.bitmapData.infoheader.bitmapWidth;
		spriteData.temp[0].frameHeight		= bitmap.bitmapData.infoheader.bitmapHeight;

		int z = spriteData.temp[0].frameWidth * spriteData.temp[0].frameHeight;

		spriteData.temp[0].p_frameData = new unsigned char[z];

		for ( int d = 0; d &lt; z; d++ )
		{
			spriteData.temp[0].p_frameData[d]	= bitmap.bitmapData.p_pixelmap[d].pixel8Bit;
		}

		// Ist das neue Frame größer als die Angabe im Header ? Ja, dann Header Updaten.
		if ( spriteData.header.spriteWidth &lt; bitmap.bitmapData.infoheader.bitmapWidth )
			spriteData.header.spriteWidth = bitmap.bitmapData.infoheader.bitmapWidth;
		if ( spriteData.header.spriteHeight &lt; bitmap.bitmapData.infoheader.bitmapHeight )
			spriteData.header.spriteHeight = bitmap.bitmapData.infoheader.bitmapHeight;
		// Frameanzahl im Header Updaten.

		spriteData.header.spriteFrames ++;
	}

	else
	{
		for ( int f = 0; f &lt; spriteData.header.spriteFrames; f++ )
		{
			if ( spriteData.frame[f].frameType == SINGLEFRAME )
			{
				spriteData.temp[f].frameType		= spriteData.frame[f].frameType;
				spriteData.temp[f].frameOriginX		= spriteData.frame[f].frameOriginX;
				spriteData.temp[f].frameOriginY		= spriteData.frame[f].frameOriginY;
				spriteData.temp[f].frameWidth		= spriteData.frame[f].frameWidth;
				spriteData.temp[f].frameHeight		= spriteData.frame[f].frameHeight;

				int z = spriteData.temp[f].frameWidth * spriteData.temp[f].frameHeight;

				spriteData.temp[f].p_frameData = new unsigned char[z];

				for ( int d = 0; d &lt; z; d++ )
				{
					spriteData.temp[f].p_frameData[d]	= spriteData.frame[f].p_frameData[d];
				}

				// Altes FrAy löschen.

// -&gt;				delete [f] spriteData.frame;
			}
			else if ( spriteData.frame[f].frameType == GROUPFRAME )
			{
				return -1;
			}
		}
		// Neues Frame hinzufügen
		spriteData.temp[newSize-1].frameType		= SINGLEFRAME;
		spriteData.temp[newSize-1].frameOriginX		= NULL;
		spriteData.temp[newSize-1].frameOriginY		= NULL;
		spriteData.temp[newSize-1].frameWidth		= bitmap.bitmapData.infoheader.bitmapWidth;
		spriteData.temp[newSize-1].frameHeight		= bitmap.bitmapData.infoheader.bitmapHeight;

		int z = bitmap.bitmapData.infoheader.bitmapWidth * bitmap.bitmapData.infoheader.bitmapHeight;

		spriteData.temp[newSize-1].p_frameData = new unsigned char[z];

		for ( int d = 0; d &lt; z; d++ )
		{
			spriteData.temp[newSize-1].p_frameData[d]	= bitmap.bitmapData.p_pixelmap[d].pixel8Bit;
		}

		// Ist das neue Frame größer als die Angabe im Header ? Ja, dann Header Updaten.
		if ( spriteData.header.spriteWidth &lt; bitmap.bitmapData.infoheader.bitmapWidth )
			spriteData.header.spriteWidth = bitmap.bitmapData.infoheader.bitmapWidth;
		if ( spriteData.header.spriteHeight &lt; bitmap.bitmapData.infoheader.bitmapHeight )
			spriteData.header.spriteHeight = bitmap.bitmapData.infoheader.bitmapHeight;
		// Frameanzahl im Header Updaten.

		spriteData.header.spriteFrames ++;
	}

	// Neues FrameArray beantragen und Temporäre Daten hineinkopieren.

	spriteData.frame = new struct c_sprite::d_sprite::d_frame[spriteData.header.spriteFrames];

	for ( int f = 0; f &lt; spriteData.header.spriteFrames; f++ )
	{
		spriteData.frame[f].frameType			= spriteData.temp[f].frameType;
		spriteData.frame[f].frameOriginX		= spriteData.temp[f].frameOriginX;
		spriteData.frame[f].frameOriginY		= spriteData.temp[f].frameOriginY;
		spriteData.frame[f].frameWidth			= spriteData.temp[f].frameWidth;
		spriteData.frame[f].frameHeight			= spriteData.temp[f].frameHeight;

		int z = spriteData.frame[f].frameWidth * spriteData.frame[f].frameHeight;

		spriteData.frame[f].p_frameData = new unsigned char[z];

		for ( int d = 0; d &lt; z; d++ )
		{
			spriteData.frame[f].p_frameData[d]	= spriteData.temp[f].p_frameData[d];
		}
		// Temporäres Fray löschen.

// -&gt;		delete [f] spriteData.temp;
	}

	return true;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1283278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1283278</guid><dc:creator><![CDATA[Pyro Phoenix]]></dc:creator><pubDate>Sat, 12 May 2007 00:57:29 GMT</pubDate></item><item><title><![CDATA[Reply to [C++] Array problem on Sat, 12 May 2007 08:53:13 GMT]]></title><description><![CDATA[<p>Du legst oft Zeiger an die noch auf was aufm Heap zeigen ... kann net gut gehen ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1283313</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1283313</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sat, 12 May 2007 08:53:13 GMT</pubDate></item><item><title><![CDATA[Reply to [C++] Array problem on Sat, 12 May 2007 09:23:10 GMT]]></title><description><![CDATA[<p>(D)Evil schrieb:</p>
<blockquote>
<p>Du legst oft Zeiger an die noch auf was aufm Heap zeigen ... kann net gut gehen ^^</p>
</blockquote>
<p><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=":confused:"
      alt="😕"
    /> Hä?<br />
Wenn mans richtig mach kann ein Zeiger überall hinzeigen und es geht gut.</p>
<p>Was du mit new anlegst wird mit delete gelöscht.<br />
Was du mit new ...[] anlegst wir dmit delete [] ... gelöscht.<br />
also</p>
<pre><code class="language-cpp">spriteData.temp[0].p_frameData = new unsigned char[z];
...
delete [] spriteData.temp[0].p_frameData;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1283327</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1283327</guid><dc:creator><![CDATA[Und auf deutsch]]></dc:creator><pubDate>Sat, 12 May 2007 09:23:10 GMT</pubDate></item><item><title><![CDATA[Reply to [C++] Array problem on Sat, 12 May 2007 10:24:10 GMT]]></title><description><![CDATA[<p>Ahso ...</p>
<p>schade ... ich dachte, ich könnte mit</p>
<p><div class="plugin-markdown"><input type="checkbox" id="checkbox297690" checked="true" /><label for="checkbox297690">array;</label></div></p>
<p>nen bestimmten array eintrag löschen.</p>
<p>aber das ging ned so recht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1283348</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1283348</guid><dc:creator><![CDATA[Pyro Phoenix]]></dc:creator><pubDate>Sat, 12 May 2007 10:24:10 GMT</pubDate></item><item><title><![CDATA[Reply to [C++] Array problem on Sat, 12 May 2007 14:04:03 GMT]]></title><description><![CDATA[<p>Dafür nimmst du std::vector (<a href="http://www.cppreference.com" rel="nofollow">www.cppreference.com</a> zum nachschlagen)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1283486</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1283486</guid><dc:creator><![CDATA[Shinja]]></dc:creator><pubDate>Sat, 12 May 2007 14:04:03 GMT</pubDate></item></channel></rss>