<?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[Ein sehr sehr sehr komischer Fehler]]></title><description><![CDATA[<p>Moin zusammen,<br />
ich habe einen wirklcih interessanten Fehler geschaffen, der mir echt Kopfzerbrechen bereietet. Ich habe eine Klasse mit einer Datenstruktur die ein Array enthält. Wenn ich jetzt mit einer Getfunktion die größe des Arrays abfrgaen will, was ein int-member der Klasse ist, werden die ersten beiden stellen des Arrays gelöscht. Warum habe ich keine Ahnung. Bei der Auskommentierten Version pasiert das gleiche übrigens. Einer von euch vielleicht? Hier ist der codekontext (die Datenstruktur, die das array enthält heißt bs):</p>
<p>//aufruf der Funktion in einer anderen klasse<br />
for (int i=0; i&lt;bs.getSize(); i++) {<br />
bs.print();<br />
int arrSize = bs[i].getDomainSize();<br />
//arrSize = bs[i].domainSize;<br />
cout &lt;&lt; i&lt;&lt;&quot; Veränderung? &quot;&lt;&lt; &quot; \n&quot;;<br />
bs.print();<br />
[...]<br />
}</p>
<p>//die getFunktion<br />
int TView ::getDomainSize() {<br />
return domainSize;<br />
}</p>
<p>//ein Teil der komischen Ausgabe:<br />
TestViewArray contains:<br />
position 0: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 1: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 2: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 3: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 4: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 5: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]</p>
<p>0 Veränderung?<br />
TestViewArray contains:<br />
position 0: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [1628722220, 1628722220, 2, 3]<br />
position 1: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 2: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 3: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 4: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 5: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]</p>
<p>Tja und so geht das weiter, jeder Schleifendurchlauf werden die ersten 2 positionen des nächsten Arrays gefressen. .. ??? ...</p>
<p>EvilEpsilon</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/156200/ein-sehr-sehr-sehr-komischer-fehler</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 21:22:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/156200.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 14 Aug 2006 15:36:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ein sehr sehr sehr komischer Fehler on Mon, 14 Aug 2006 15:36:03 GMT]]></title><description><![CDATA[<p>Moin zusammen,<br />
ich habe einen wirklcih interessanten Fehler geschaffen, der mir echt Kopfzerbrechen bereietet. Ich habe eine Klasse mit einer Datenstruktur die ein Array enthält. Wenn ich jetzt mit einer Getfunktion die größe des Arrays abfrgaen will, was ein int-member der Klasse ist, werden die ersten beiden stellen des Arrays gelöscht. Warum habe ich keine Ahnung. Bei der Auskommentierten Version pasiert das gleiche übrigens. Einer von euch vielleicht? Hier ist der codekontext (die Datenstruktur, die das array enthält heißt bs):</p>
<p>//aufruf der Funktion in einer anderen klasse<br />
for (int i=0; i&lt;bs.getSize(); i++) {<br />
bs.print();<br />
int arrSize = bs[i].getDomainSize();<br />
//arrSize = bs[i].domainSize;<br />
cout &lt;&lt; i&lt;&lt;&quot; Veränderung? &quot;&lt;&lt; &quot; \n&quot;;<br />
bs.print();<br />
[...]<br />
}</p>
<p>//die getFunktion<br />
int TView ::getDomainSize() {<br />
return domainSize;<br />
}</p>
<p>//ein Teil der komischen Ausgabe:<br />
TestViewArray contains:<br />
position 0: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 1: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 2: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 3: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 4: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 5: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]</p>
<p>0 Veränderung?<br />
TestViewArray contains:<br />
position 0: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [1628722220, 1628722220, 2, 3]<br />
position 1: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 2: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 3: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 4: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]<br />
position 5: TestView (domainsize: 4 , constantSize: 4, max: 3 , min: 0)<br />
contains: [0, 1, 2, 3]</p>
<p>Tja und so geht das weiter, jeder Schleifendurchlauf werden die ersten 2 positionen des nächsten Arrays gefressen. .. ??? ...</p>
<p>EvilEpsilon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1117076</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1117076</guid><dc:creator><![CDATA[EvilEpsilon]]></dc:creator><pubDate>Mon, 14 Aug 2006 15:36:03 GMT</pubDate></item><item><title><![CDATA[Reply to Ein sehr sehr sehr komischer Fehler on Mon, 14 Aug 2006 15:43:27 GMT]]></title><description><![CDATA[<p>die klassendefinition solltest du uns nicht vorenthalten. bitte geeignete code-tags benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1117082</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1117082</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 14 Aug 2006 15:43:27 GMT</pubDate></item><item><title><![CDATA[Reply to Ein sehr sehr sehr komischer Fehler on Mon, 14 Aug 2006 15:44:31 GMT]]></title><description><![CDATA[<p>poste mal den ganzen Code</p>
<p>EDIT: loool, mal wieder 2 Posts zur selben Zeit <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1117083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1117083</guid><dc:creator><![CDATA[ESS_CB]]></dc:creator><pubDate>Mon, 14 Aug 2006 15:44:31 GMT</pubDate></item><item><title><![CDATA[Reply to Ein sehr sehr sehr komischer Fehler on Mon, 14 Aug 2006 15:58:05 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">//Tview: 
class TView {
	public:
		int* domain;
		int max;
		int min;
		int domainSize; //can shrink if one value is dropped
		int conSize; //constant
		string name;
public:
	TView() {
            domain = NULL;
            max =0;
            min = 0;
            domainSize=0;
            conSize = 0;
            name  = &quot; &quot;;
    }

 void TView::init(int pDomainSize, int pRangeMin, int pRangeMax, string pName) {
    conSize = pDomainSize;
    domainSize = pDomainSize;
    //TODO conSize initialisiert??
    domain = new int[conSize];
    min = pRangeMin;
    max = pRangeMax;
    name = pName;
    if (max - min != conSize-1) {
       cout &lt;&lt; &quot;Error in TView() for range domain: range does not fit in array size, corrected\n&quot;;
       max = min + conSize - 1;
    }
    for (int i=0; i&lt;conSize; i++)
        domain[i] = i+min;
  }

	~TView() {
		delete domain;
	}

	void TView ::print() {
		cout &lt;&lt; &quot;TestView &quot; &lt;&lt; name &lt;&lt; &quot; (domainsize: &quot;&lt;&lt; domainSize &lt;&lt;&quot; , constantSize: &quot; &lt;&lt; conSize &lt;&lt;&quot;, max: &quot; &lt;&lt; max &lt;&lt; &quot; , min: &quot; &lt;&lt; min &lt;&lt; &quot;) \n   contains: [&quot;;
		for (int i=0; i&lt;conSize; i++) {
			if (i&lt; conSize -1) cout &lt;&lt; domain[i] &lt;&lt; &quot;, &quot;;
			else cout &lt;&lt; domain[i] ;
		}
		cout &lt;&lt; &quot;]\n&quot;;
	}

  //returns index of value or -1 if it is not contained in domain
  int TView ::find(int val) {
       for (int i=0; i&lt; conSize; i++)
           if (domain[i] == val) return i;
       return -1;
  }

  //returns domainArray without -1 values (empty positions)
  //if domain empty: return value = NULL
  int* TView ::getDomain() {
        if (domainSize == 0) {
           cout &lt;&lt; &quot;in Tview.getDomain: domain is empty!\n&quot;;
           return NULL;
        }
        int* ret =new int[domainSize];
        int countPos=0; //
        for (int i=0; i&lt; conSize; i++) {
            if (domain[i]!= -1) {
               ret[countPos] = domain[i];
               countPos++;
            }
        }
        return ret;
  }

  int TView ::getDomainSize() {
      //cout &lt;&lt;&quot;hier\n&quot;;
      //print();
      return domainSize;
  }

  int TView:: getMin() {
      return min;
  }

  int TView:: getMax() {
      return max;
  }

};

//---------------------------------------------------------------------
class TViewArray {
      public:
	TView* array;
	int size;
	string name;

   //constructor for range domain variable array
   //random = true: RangeMin and Max are random values in the given interval
   //or if RangeMax - RangeMin &lt; 4
   TViewArray (int pSize, int pRangeMin, int pRangeMax, bool random, string pName) {
       cout &lt;&lt; &quot;ich war hier in TviewArray\n&quot;;
       size = pSize;
       name = pName;
       array = new TView[size];
       if (random == false || pRangeMax - pRangeMin &lt; 4) {
          int dSize = 0;
          dSize = pRangeMax - pRangeMin +1;
          cout &lt;&lt; &quot;DSize &quot; &lt;&lt; dSize &lt;&lt; &quot; pRangeMax &quot; &lt;&lt;pRangeMax &lt;&lt; &quot; pRangeMin &quot; &lt;&lt;pRangeMin &lt;&lt;endl;
          for (int i=0; i&lt; size; i++){
              cout &lt;&lt; &quot;ich kam bis hier in TviewArray.. bla&quot;&lt;&lt;i &lt;&lt;&quot;\n&quot;;
              //TView element (dSize, pRangeMin, pRangeMax, &quot; &quot;);
              array[i].init(dSize, pRangeMin, pRangeMax, &quot; &quot;);
          }
          cout &lt;&lt; &quot;ich kam bis hier in TviewArray\n&quot;;
       }

       else {
          int min = 0, max = 0, dSize = 0;
          for (int i=0; i&lt; size; i++){
              min = rand() % pRangeMax + pRangeMin;
              max = rand() % pRangeMax+ 2 + min ;
              dSize = max - min +1;
              //cout &lt;&lt; &quot;bla &quot; &lt;&lt; min &lt;&lt; &quot; &quot; &lt;&lt; max &lt;&lt; &quot; &quot; &lt;&lt; dSize &lt;&lt; endl;

              array[i].init(dSize, min, max, &quot; &quot;);
          }
       }
   }

	 TView TViewArray ::operator[](int i) {
        //assert((i &gt;= 0) &amp;&amp; (i &lt; size));
        return array[i];
     }

     ~TViewArray() {
        }     }

     void TViewArray ::print() {
          cout &lt;&lt; &quot;TestViewArray contains: &quot; &lt;&lt; endl;
          for (int i=0; i&lt; size; i++) {
              cout &lt;&lt; &quot;   position &quot; &lt;&lt; i &lt;&lt; &quot;: &quot;;
              //if (array[i] != NULL )
              array[i].print();
              //cout &lt;&lt; &quot;bla bla &quot; &lt;&lt; i &lt;&lt; endl;
          }
          cout &lt;&lt; endl;
     }
     int TViewArray ::getSize() {
         return size;
     }

};

//--------------------------------------------------------------
class BppGrund {
    public: 
             //changing values required for calculations 
             //Sets: for every bin
             SetVector possibleSet; 
             SetVector requiredSet; 
             SetVector candidateSet; 
             bool* unpackedItems;
             TViewArray l; 
             TViewArray bs; 

             //constant or given values
             int loadLimit;
             int totalSize; //sum of all itemSizes
             int* itemSizes;
             int amountOfItems;
     public: 

             BppGrund(int n, int ll, int s[], int itemSum, int usedBins): 
                possibleSet(usedBins, &quot;possibleSet&quot;),
                requiredSet(usedBins, &quot;requiredSet&quot;),
                candidateSet(usedBins, &quot;candidateSet&quot;),

                l (usedBins, 0, itemSum, false, &quot;l&quot;),

                bs (n, 0, usedBins, false, &quot;b&quot;)
                {
                 //Set constant parameters
                 cout &lt;&lt; &quot;hier anfang&quot; &lt;&lt; endl;
                 amountOfItems = n;
                 loadLimit = ll;
                 //TODO Fehler abfangen: parametercheck n&gt;0 etc, Größe intArray == n
                 itemSizes = new int[n];
                 totalSize = itemSum;

                 amountOfUsedBins = totalSize / loadLimit;

                 unpackedItems = new bool[amountOfItems];
                 for (int i=0; i++; i&lt;n)
                     unpackedItems[i] = false;

                 cout &lt;&lt; &quot;hier zwischen&quot; &lt;&lt; endl;

                 //TODO Sets initialisieren
                  cout &lt;&lt; &quot;hier ende&quot; &lt;&lt; endl;
             }

             ~BppGrund() {}       

             void initSets() {
                 int arrSize = 0;
                 for (int i=0; i&lt;bs.getSize(); i++) {
                     bs.print();
                     //TODO hier den komicshen FEhler rauswerfen. 
                     int arrSize = bs[i].getDomainSize();
                     //arrSize = bs[i].domainSize;
                     cout &lt;&lt; i&lt;&lt;&quot; Veränderung? &quot;&lt;&lt; &quot; \n&quot;;
                     bs.print();
                     int* arr = bs.getDomainAt(i);
                     if (arr == NULL || arrSize == 0) continue;
                     possibleSet.addManyToItemSets(arr, i,itemSizes[i], arrSize );
                     if (arrSize == 1) requiredSet.addManyToItemSets(arr, i,itemSizes[i], arrSize );
                     else candidateSet.addManyToItemSets(arr, i,itemSizes[i], arrSize );
                 } 
             }
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1117093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1117093</guid><dc:creator><![CDATA[EvilEpsilon]]></dc:creator><pubDate>Mon, 14 Aug 2006 15:58:05 GMT</pubDate></item><item><title><![CDATA[Reply to Ein sehr sehr sehr komischer Fehler on Mon, 14 Aug 2006 16:37:10 GMT]]></title><description><![CDATA[<p>omg?!</p>
<p>ich habe jetzt beim durchschauen nichts gefunden. Probiers mal mit Debuggen. Die ersten beiden array müssen irgendwo neu erstellt worden sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1117123</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1117123</guid><dc:creator><![CDATA[ESS_CB]]></dc:creator><pubDate>Mon, 14 Aug 2006 16:37:10 GMT</pubDate></item><item><title><![CDATA[Reply to Ein sehr sehr sehr komischer Fehler on Tue, 15 Aug 2006 13:09:39 GMT]]></title><description><![CDATA[<p>EvilEpsilon schrieb:</p>
<blockquote>
<pre><code class="language-cpp">...
class TViewArray {
...
    TView TViewArray ::operator[](int i) {
        return array[i];
     }
...
};
...
</code></pre>
</blockquote>
<p>Hi,</p>
<p>obs was damit zu tun hat, weiß ich nicht, aber mich wundert ein wenig, dass der operator[]() per Wert zurückliefert ... das bedeutet, dass ein temporäres TView-Objekt erzeugt und zurückgeliefert wird.</p>
<p>Verbunden damit, dass TView dynamisch Speicher erzeugt, aber keinen (selbstgeschriebenen) CpyCtor/operator=() bereitstellt, macht mich stutzig.</p>
<p>üblicherweise deklariert man</p>
<pre><code class="language-cpp">const T&amp; operator[](size_t i);
</code></pre>
<p>oder wenn der Client die Alemente ändern können soll:</p>
<pre><code class="language-cpp">T&amp; operator[](size_t i);
</code></pre>
<p>und verhindert damit automatische Kopien.</p>
<p>EDIT sagt noch, dass man nach einem new[] auch ein delete[] aufrufen sollte ....</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1117575</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1117575</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Tue, 15 Aug 2006 13:09:39 GMT</pubDate></item><item><title><![CDATA[Reply to Ein sehr sehr sehr komischer Fehler on Wed, 16 Aug 2006 07:05:54 GMT]]></title><description><![CDATA[<p>Ja danke aber wie geht das?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118013</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118013</guid><dc:creator><![CDATA[EvilEpsilon]]></dc:creator><pubDate>Wed, 16 Aug 2006 07:05:54 GMT</pubDate></item><item><title><![CDATA[Reply to Ein sehr sehr sehr komischer Fehler on Wed, 16 Aug 2006 08:05:19 GMT]]></title><description><![CDATA[<p>Deine Pointer auf int, bool etc. sind ja sowieso nur Arrays. Da wäre es am einfachsten gleich vector zu verwenden. Dann kannst du dir nämlich deinen eigenen Kopierkonstruktor usw. sparen.<br />
Ansonsten lies einfach mal das hier<br />
<a href="http://tutorial.schornboeck.net/bigthree.htm" rel="nofollow">http://tutorial.schornboeck.net/bigthree.htm</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118038</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118038</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 16 Aug 2006 08:05:19 GMT</pubDate></item><item><title><![CDATA[Reply to Ein sehr sehr sehr komischer Fehler on Wed, 16 Aug 2006 08:42:50 GMT]]></title><description><![CDATA[<p>EvilEpsilon schrieb:</p>
<blockquote>
<p>Ja danke aber wie geht das?</p>
</blockquote>
<p>Was genau ?<br />
- operator[]() per Reference ? Einfach Returntyp anders deklarieren (&quot;const TView&amp;&quot; bzw. &quot;TView&amp;&quot; statt &quot;TView&quot;). Darfst natürlich nicht selbst eine Kopie zurückgeben (machst Du aber zeit auch nicht)<br />
- delete[] verwenden ? einfach statt &quot;delete&quot; &quot;delete[]&quot; schreiben.</p>
<p>Allerdings ist Braunsteins Einwand schon gerechtfertigt: Wenn Du nicht selbst lernen willst, Container zu schreiben, solltest Du die STL-Container (am einfachsten std::vector) verwenden ... die nehmen Dir das alles ab.</p>
<p>Wenn Du unbedingt selbst eine Array-Klasse schreiben willst, solltest Du noch etwas besser auf Deinen Speicherhaushalt achten. Mir ist z.B. nicht ganz klar, wem jetzt eigentlich eine &quot;domain&quot; gehört, die in getDomain() erzeugt wird ... wer löscht die denn wieder ? Ist es wirklich so, dass der Aufrufer eine eigene Kopie davon bekommen soll ?</p>
<p>Mir scheint, dass Du die Dinge unnötig verkomplizierst ... schreib doch mal, was so ein View eigentlich ist und wer was mit einer Menge von Views anfangen soll.</p>
<p>BTW: Ich habe nirgendwo die Deklaration oder Dfinition von &quot;getDomainAt()&quot; gefinden.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118066</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118066</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Wed, 16 Aug 2006 08:42:50 GMT</pubDate></item><item><title><![CDATA[Reply to Ein sehr sehr sehr komischer Fehler on Fri, 18 Aug 2006 10:07:39 GMT]]></title><description><![CDATA[<p>ja danke nochmal für die ideen. hab das intarray jetzt in eine map umgewandelt und damit läufts... ist auch nur ne testklasse das ding, also muß nur funktionieren. <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="🙂"
    /> *mir erlaub unschöne sachen zu programmieren*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1119711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1119711</guid><dc:creator><![CDATA[EvilEpsilon]]></dc:creator><pubDate>Fri, 18 Aug 2006 10:07:39 GMT</pubDate></item></channel></rss>