<?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[Fehler?]]></title><description><![CDATA[<p>GCC beschwert sich über einen Teil in meiner Klasse und ich habe irgendwie nicht ganz verstanden, was dem Compiler da nicht passt. Der grobe Aufbau:</p>
<pre><code class="language-cpp">class is_ja_auch_egal {
  ...
  public:
    int_table() {
        int a=20;
        this-&gt;integers = new int[a];
        this-&gt;chars    = new char*[a];
        max=a;
        position=0; }

    ~int_table() {
        position=max=0;
        delete[] integers; integers=0;
        delete[] chars; chars=0; }

    ...

    int new_value(char *name, int integer) {
        if(position==max) {

        ...

        const short x=32, y=64;

            int *temp_int=new int[max];
            char *temp_char[max]; // Das sollen die &quot;Auffangbehälter&quot; für chars und integers sein

            for(int i=0;i&lt;max;i++) {
                temp_char[i]=new char[y];
                util::cpystrn(temp_char[i], chars[i]);
                temp_int[i]=integers[i]; } // Umkopieraktion

            max+=20;

            delete[] integers; integers=0;
            delete[] chars; chars=0;

            integers = new int[max];
            chars    = new char*[max];

            for(int i=0;i&lt;(max-20);i++) {
                chars[i]=new char[y];
                util::cpystrn(chars[i], temp_char[i]);
                integers[i]=temp_int[i]; } // Zurückkopieraktion

            delete[] temp_int; temp_int=0;
            delete[] temp_char; temp_char=0; // &lt;-- Beschwerde
            }

        ...

        position++;

        return 0; }

    ...

    private:
        int  position;
        int  max;
        int  *integers;
        char **chars;
     };
</code></pre>
<p>Ich habe nicht ganz herauslesen können, warum der Compiler den ersten delete[]-Block hinnimmt und mir beim 2. was von</p>
<blockquote>
<p>150 C:\Dev\src\Projects\UNCI\parser.cpp [Warning] deleting array <code>char\*temp\_char\[((unsigned int)((int)((int\_table\*)this)-&gt;int_table::max))\]' 150 C:\\Dev\\src\\Projects\\UNCI\\parser.cpp incompatible types in assignment of \</code>int' to `char*[((unsigned int)((int)((int_table*)this)-&gt;int_table::max))]'</p>
</blockquote>
<p>erzählt. Schreibe ich stattdessen <strong>delete[] *temp_char; *temp_char=0;</strong> in die betreffende Zeile hält der Compiler die Klappe aber warum habe ich auch nicht so ganz vestanden...</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/118952/fehler</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 18:57:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/118952.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 25 Aug 2005 23:00:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler? on Thu, 25 Aug 2005 23:15:54 GMT]]></title><description><![CDATA[<p>GCC beschwert sich über einen Teil in meiner Klasse und ich habe irgendwie nicht ganz verstanden, was dem Compiler da nicht passt. Der grobe Aufbau:</p>
<pre><code class="language-cpp">class is_ja_auch_egal {
  ...
  public:
    int_table() {
        int a=20;
        this-&gt;integers = new int[a];
        this-&gt;chars    = new char*[a];
        max=a;
        position=0; }

    ~int_table() {
        position=max=0;
        delete[] integers; integers=0;
        delete[] chars; chars=0; }

    ...

    int new_value(char *name, int integer) {
        if(position==max) {

        ...

        const short x=32, y=64;

            int *temp_int=new int[max];
            char *temp_char[max]; // Das sollen die &quot;Auffangbehälter&quot; für chars und integers sein

            for(int i=0;i&lt;max;i++) {
                temp_char[i]=new char[y];
                util::cpystrn(temp_char[i], chars[i]);
                temp_int[i]=integers[i]; } // Umkopieraktion

            max+=20;

            delete[] integers; integers=0;
            delete[] chars; chars=0;

            integers = new int[max];
            chars    = new char*[max];

            for(int i=0;i&lt;(max-20);i++) {
                chars[i]=new char[y];
                util::cpystrn(chars[i], temp_char[i]);
                integers[i]=temp_int[i]; } // Zurückkopieraktion

            delete[] temp_int; temp_int=0;
            delete[] temp_char; temp_char=0; // &lt;-- Beschwerde
            }

        ...

        position++;

        return 0; }

    ...

    private:
        int  position;
        int  max;
        int  *integers;
        char **chars;
     };
</code></pre>
<p>Ich habe nicht ganz herauslesen können, warum der Compiler den ersten delete[]-Block hinnimmt und mir beim 2. was von</p>
<blockquote>
<p>150 C:\Dev\src\Projects\UNCI\parser.cpp [Warning] deleting array <code>char\*temp\_char\[((unsigned int)((int)((int\_table\*)this)-&gt;int_table::max))\]' 150 C:\\Dev\\src\\Projects\\UNCI\\parser.cpp incompatible types in assignment of \</code>int' to `char*[((unsigned int)((int)((int_table*)this)-&gt;int_table::max))]'</p>
</blockquote>
<p>erzählt. Schreibe ich stattdessen <strong>delete[] *temp_char; *temp_char=0;</strong> in die betreffende Zeile hält der Compiler die Klappe aber warum habe ich auch nicht so ganz vestanden...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/858703</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/858703</guid><dc:creator><![CDATA[BloodLord]]></dc:creator><pubDate>Thu, 25 Aug 2005 23:15:54 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler? on Fri, 26 Aug 2005 00:22:34 GMT]]></title><description><![CDATA[<p>Ein Fehler ist zum Beispiel das du zuviel Code postest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/858705</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/858705</guid><dc:creator><![CDATA[meinung]]></dc:creator><pubDate>Fri, 26 Aug 2005 00:22:34 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler? on Fri, 26 Aug 2005 00:45:46 GMT]]></title><description><![CDATA[<p>temp_char ist ein Array und wird somit auf dem Stack angelegt und automatisch gelöscht wenn der Gültigkeitsbereich verlassen wird. Deshalb kannst du auch nicht delete darauf anwenden. Normalerweise sollte das mit dem Array so nicht funktionieren wenn max nicht konstant ist.<br />
Mit *<em>delete[] <em>temp_char;</em></em> würdest du aus deinem Pointerarray den ersten Pointer an delete[] übergeben und somit würde dieses Element gelöscht werden. In deinem jetzigen Code löscht du zwar die Pointer-Arrays aber die Elemente nicht und erzeugst somit ein Memory Leak.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/858707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/858707</guid><dc:creator><![CDATA[masterofx32]]></dc:creator><pubDate>Fri, 26 Aug 2005 00:45:46 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler? on Fri, 26 Aug 2005 22:28:53 GMT]]></title><description><![CDATA[<p>Stimmt könnte leaks geben <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="😉"
    /> Okay dann also besser einfach die Zweite for etwas ergänzen...</p>
<pre><code class="language-cpp">...

for(int i=0;i&lt;(max-20);i++) {
   chars[i]=new char[y];
   util::cpystrn(chars[i], temp_char[i]);
   integers[i]=temp_int[i];
   delete[] temp_char[i]; } // das sollte es normal beheben, nicht?

delete[] temp_int;  temp_int=0;
 delete[] *temp_char; *temp_char=0; // &lt;-- Müsste ja aber überflüssig sein

...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/859392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/859392</guid><dc:creator><![CDATA[BloodLord]]></dc:creator><pubDate>Fri, 26 Aug 2005 22:28:53 GMT</pubDate></item></channel></rss>