<?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[copyconstructor baut misst]]></title><description><![CDATA[<p>hi,.. leuts,..<br />
also im ersten fall funktioniert der copyconstructer wie er sollte,. im zwoten wieder nicht,.. meine frage wieso????<br />
(...weitere erläuterung weiter unten...)</p>
<p>hier einmal der wesentliche source für die ausgabe:</p>
<pre><code>//---class whole_number_Type

whole_number_type::whole_number_type(const whole_number_type &amp;b)
       {
         cout&lt;&lt;endl&lt;&lt;&quot;copy constructor:&quot;&lt;&lt;endl;
         count=b.count;                                  
         delete pBinary_array;
         pBinary_array=new bool[count];//cout&lt;&lt;endl;
         for(long int i=0;i&lt;count;i++){pBinary_array[i]=b.pBinary_array[i];}
         for(long int i=0;i&lt;count;i++){ cout&lt;&lt;b.pBinary_array[i];}
         sign_of_binary_array=b.sign_of_binary_array; cout&lt;&lt;endl;      
       };
whole_number_type &amp;whole_number_type::operator+(const whole_number_type &amp;obj) 
       {
         whole_number_type a(*this);

         long int counting=0;
         bool *aArray;
         bool *bArray;
         bool *cArray;
         bool *car_ray;
         bool carry=0;
         bool old_carry=0;
         //first we have to check  which #counts are higher
         if(count &gt;= obj.count) 
         {counting=a.count+1;}
         else {counting=obj.count+1; };

         //check signes
         aArray=new bool[counting];
         bArray=new bool[counting];
         cArray=new bool[counting];
         car_ray=new bool[counting];
         for(long int i=0;i&lt;counting;i++)
         {aArray[i]=false; bArray[i]=false; cArray[i]=false;car_ray[i]=false;};
          for(long int i=0;i&lt;obj.count;i++)
         {aArray[i]=a.pBinary_array[i];}; 
         for(long int i=0;i&lt;obj.count;i++)
         {bArray[i]=obj.pBinary_array[i];};         
          //cout&lt;&lt;endl;
          //for(long int i=0;i&lt;counting-1;i++){cout&lt;&lt;aArray[i];};cout&lt;&lt;endl;
          // for(long int i=0;i&lt;counting-1;i++){cout&lt;&lt;bArray[i];};
         if((a.sign_of_binary_array)&amp;&amp;(obj.sign_of_binary_array))//k we can add
         {                     
          bool temp=0;
          //cout&lt;&lt;endl;
          for(long int i=0;i&lt;counting-1;i++)
          {                     
           temp=(aArray[i]^bArray[i]);
           car_ray[i+1]=((aArray[i]&amp;&amp;bArray[i])||(temp&amp;&amp;car_ray[i])); 
           cArray[i]=car_ray[i]^temp;
          // cout&lt;&lt;aArray[i]&lt;&lt;bArray[i]&lt;&lt;car_ray[i]&lt;&lt;&quot; &quot;&lt;&lt;cArray[i]&lt;&lt;endl;

          }                      
          a.sign_of_binary_array=obj.sign_of_binary_array; 
         }
         else{

              }

         delete a.pBinary_array;
         //cout&lt;&lt;counting-1;
         a.count=counting;                    
         a.pBinary_array=new bool[counting];
         //cout&lt;&lt;endl;
         a.pBinary_array[counting-1]=car_ray[counting-1];
         for(long int i=0;i&lt;counting-1;i++)
         {a.pBinary_array[i]=cArray[i];cout&lt;&lt;a.pBinary_array[i];}
          cout&lt;&lt;a.pBinary_array[counting-1]&lt;&lt;endl;

         return a;
         };

//-----main

whole_number_type k(8);
whole_number_type g(8);
whole_number_type h(8);
k=one;cout&lt;&lt;endl;
h=two;cout&lt;&lt;endl;
g=k+h;cout&lt;&lt;endl;
k.print();
h.print();
g.print();

whole_number_type i(8);
whole_number_type j(8);
whole_number_type l(8);
i=three;cout&lt;&lt;endl;
j=four;cout&lt;&lt;endl;
l=i+j;cout&lt;&lt;endl;
i.print();
j.print();
l.print();
</code></pre>
<p>ok und hier die ausgabe:</p>
<pre><code>copy constructor:
01011001
000010110 &lt;- 1.a

copy constructor:
000010110 &lt;- 1.b

01011001
01101100
000010110 &lt;- 1.c

copy constructor:
01110110
101000010 &lt;- 2.a

copy constructor:
000000010 &lt;- 2.b ??????

01110110
11101000
000000010 &lt;- 2.c
Drücken Sie eine beliebige Taste . . .
</code></pre>
<p>ok,. fall x.a ist das ergebniss der addition,<br />
der fall x.b der aufruf des copyconstructors vor '='<br />
und x.c der aufruf der methode print(),...<br />
kann mir jemand helfen?? ich habe keine ahnung woran das liegt,..</p>
<p>seid gegrüßt</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/207240/copyconstructor-baut-misst</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Apr 2026 05:17:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/207240.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 05 Mar 2008 10:28:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 10:32:53 GMT]]></title><description><![CDATA[<p>hi,.. leuts,..<br />
also im ersten fall funktioniert der copyconstructer wie er sollte,. im zwoten wieder nicht,.. meine frage wieso????<br />
(...weitere erläuterung weiter unten...)</p>
<p>hier einmal der wesentliche source für die ausgabe:</p>
<pre><code>//---class whole_number_Type

whole_number_type::whole_number_type(const whole_number_type &amp;b)
       {
         cout&lt;&lt;endl&lt;&lt;&quot;copy constructor:&quot;&lt;&lt;endl;
         count=b.count;                                  
         delete pBinary_array;
         pBinary_array=new bool[count];//cout&lt;&lt;endl;
         for(long int i=0;i&lt;count;i++){pBinary_array[i]=b.pBinary_array[i];}
         for(long int i=0;i&lt;count;i++){ cout&lt;&lt;b.pBinary_array[i];}
         sign_of_binary_array=b.sign_of_binary_array; cout&lt;&lt;endl;      
       };
whole_number_type &amp;whole_number_type::operator+(const whole_number_type &amp;obj) 
       {
         whole_number_type a(*this);

         long int counting=0;
         bool *aArray;
         bool *bArray;
         bool *cArray;
         bool *car_ray;
         bool carry=0;
         bool old_carry=0;
         //first we have to check  which #counts are higher
         if(count &gt;= obj.count) 
         {counting=a.count+1;}
         else {counting=obj.count+1; };

         //check signes
         aArray=new bool[counting];
         bArray=new bool[counting];
         cArray=new bool[counting];
         car_ray=new bool[counting];
         for(long int i=0;i&lt;counting;i++)
         {aArray[i]=false; bArray[i]=false; cArray[i]=false;car_ray[i]=false;};
          for(long int i=0;i&lt;obj.count;i++)
         {aArray[i]=a.pBinary_array[i];}; 
         for(long int i=0;i&lt;obj.count;i++)
         {bArray[i]=obj.pBinary_array[i];};         
          //cout&lt;&lt;endl;
          //for(long int i=0;i&lt;counting-1;i++){cout&lt;&lt;aArray[i];};cout&lt;&lt;endl;
          // for(long int i=0;i&lt;counting-1;i++){cout&lt;&lt;bArray[i];};
         if((a.sign_of_binary_array)&amp;&amp;(obj.sign_of_binary_array))//k we can add
         {                     
          bool temp=0;
          //cout&lt;&lt;endl;
          for(long int i=0;i&lt;counting-1;i++)
          {                     
           temp=(aArray[i]^bArray[i]);
           car_ray[i+1]=((aArray[i]&amp;&amp;bArray[i])||(temp&amp;&amp;car_ray[i])); 
           cArray[i]=car_ray[i]^temp;
          // cout&lt;&lt;aArray[i]&lt;&lt;bArray[i]&lt;&lt;car_ray[i]&lt;&lt;&quot; &quot;&lt;&lt;cArray[i]&lt;&lt;endl;

          }                      
          a.sign_of_binary_array=obj.sign_of_binary_array; 
         }
         else{

              }

         delete a.pBinary_array;
         //cout&lt;&lt;counting-1;
         a.count=counting;                    
         a.pBinary_array=new bool[counting];
         //cout&lt;&lt;endl;
         a.pBinary_array[counting-1]=car_ray[counting-1];
         for(long int i=0;i&lt;counting-1;i++)
         {a.pBinary_array[i]=cArray[i];cout&lt;&lt;a.pBinary_array[i];}
          cout&lt;&lt;a.pBinary_array[counting-1]&lt;&lt;endl;

         return a;
         };

//-----main

whole_number_type k(8);
whole_number_type g(8);
whole_number_type h(8);
k=one;cout&lt;&lt;endl;
h=two;cout&lt;&lt;endl;
g=k+h;cout&lt;&lt;endl;
k.print();
h.print();
g.print();

whole_number_type i(8);
whole_number_type j(8);
whole_number_type l(8);
i=three;cout&lt;&lt;endl;
j=four;cout&lt;&lt;endl;
l=i+j;cout&lt;&lt;endl;
i.print();
j.print();
l.print();
</code></pre>
<p>ok und hier die ausgabe:</p>
<pre><code>copy constructor:
01011001
000010110 &lt;- 1.a

copy constructor:
000010110 &lt;- 1.b

01011001
01101100
000010110 &lt;- 1.c

copy constructor:
01110110
101000010 &lt;- 2.a

copy constructor:
000000010 &lt;- 2.b ??????

01110110
11101000
000000010 &lt;- 2.c
Drücken Sie eine beliebige Taste . . .
</code></pre>
<p>ok,. fall x.a ist das ergebniss der addition,<br />
der fall x.b der aufruf des copyconstructors vor '='<br />
und x.c der aufruf der methode print(),...<br />
kann mir jemand helfen?? ich habe keine ahnung woran das liegt,..</p>
<p>seid gegrüßt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468609</guid><dc:creator><![CDATA[zeusosc]]></dc:creator><pubDate>Wed, 05 Mar 2008 10:32:53 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 10:34:48 GMT]]></title><description><![CDATA[<p>Warum ruft dein Copykonstruktor delete auf? Es gibt keinen &quot;alten&quot; Inhalt, der gelöscht werden müsste.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468619</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 05 Mar 2008 10:34:48 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 10:38:39 GMT]]></title><description><![CDATA[<p>weil sonst dass passiert:</p>
<pre><code>copy constructor:
160261016026100
</code></pre>
<p>und ich bin hier praktisch <span class="katex"><span class="katex-mathml"><math><semantics><mrow><msubsup><mrow><mi mathvariant="double-struck">Z</mi></mrow><mn>2</mn><mi>n</mi></msubsup></mrow><annotation encoding="application/x-tex">\mathbb{Z}^n_2</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.68889em;"></span><span class="strut bottom" style="height:0.936998em;vertical-align:-0.24810799999999997em;"></span><span class="base textstyle uncramped"><span class=""><span class="mord textstyle uncramped"><span class="mord mathbb">Z</span></span><span class="vlist"><span style="top:0.24810799999999997em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle cramped"><span class="mord mathrm">2</span></span></span><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord mathit">n</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span></span></span></span><br />
gruuuß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468624</guid><dc:creator><![CDATA[zeusosc]]></dc:creator><pubDate>Wed, 05 Mar 2008 10:38:39 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 10:44:55 GMT]]></title><description><![CDATA[<p>zeusosc schrieb:</p>
<blockquote>
<p>weil sonst dass passiert:</p>
<pre><code>copy constructor:
160261016026100
</code></pre>
</blockquote>
<p>Mag ja sein, ist trotzdem falsch.</p>
<p>Dein operator+ gibt übrigens eine Referenz auf eine lokale Variable zurück.</p>
<p>Warum plagst du dich eigentlich mit Arrays ab, und benutzt nicht std::vector?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468631</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468631</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 05 Mar 2008 10:44:55 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 10:55:02 GMT]]></title><description><![CDATA[<p>weil geplant ist mehrere tausend klassen aufzurufen,..<br />
und ::vector braucht dann ne menge speicherplatz,..<br />
da habe ich halt gehofft das ein bool'sches array net so viel braucht,..</p>
<p>gruuß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468641</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468641</guid><dc:creator><![CDATA[zeusosc]]></dc:creator><pubDate>Wed, 05 Mar 2008 10:55:02 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 10:58:22 GMT]]></title><description><![CDATA[<p>zeusosc schrieb:</p>
<blockquote>
<p>weil geplant ist mehrere tausend klassen aufzurufen,..<br />
und ::vector braucht dann ne menge speicherplatz,..</p>
</blockquote>
<p>Ein vector&lt;bool&gt; dürfte um ein vielfaches effizienter sein (zumindest was den Speicherverbrauch angeht) als dein Array-Gebastel. Mit dem Zusatznutzen, dass es funktioniert, und du weder Copykonstruktor noch Zuweisungsoperator oder Destruktor selbst zu schreiben brauchst.</p>
<p>zeusosc schrieb:</p>
<blockquote>
<p>da habe ich halt gehofft das ein bool'sches array net so viel braucht,..</p>
</blockquote>
<p>Du weißt aber, dass ein vector innen drin normalerweise auch nur ein Array ist, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468644</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 05 Mar 2008 10:58:22 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 11:05:11 GMT]]></title><description><![CDATA[<p>so weit ich weiß is std::vector ein container,...</p>
<p>gruuuß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468650</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468650</guid><dc:creator><![CDATA[zeusosc]]></dc:creator><pubDate>Wed, 05 Mar 2008 11:05:11 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 11:10:31 GMT]]></title><description><![CDATA[<p>ja, std::vector ist ein container, aber der verwendet in der regel intern einfach ein array, das mit new dynamisch erzeugt wird.<br />
und ein array von bool[] verbraucht sogar *mit sicherheit* mehr speicher als ein vector&lt;bool&gt;, denn sizeof(bool) ist niemals weniger als ein byte und vector&lt;bool&gt; packt idR bools intern tatsächlich in einzelne bits.</p>
<p>vector&lt;bool&gt; ist übrigens kein container.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468654</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Wed, 05 Mar 2008 11:10:31 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 11:14:53 GMT]]></title><description><![CDATA[<p>ok,. danke für die info,..</p>
<p>ich verbleibe erstmal bei einem bool array[] und würde gerne wissen wo im copyconstructor der fehler liegt, bzw. das gerade beim ersten alles richtig läuft und beim zweiten aufruf ein paar bits verschluckt werden,....</p>
<p>gruuuß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468659</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468659</guid><dc:creator><![CDATA[zeusosc]]></dc:creator><pubDate>Wed, 05 Mar 2008 11:14:53 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 11:18:02 GMT]]></title><description><![CDATA[<p>zeusosc schrieb:</p>
<blockquote>
<p>ich verbleibe erstmal bei einem bool array[] und würde gerne wissen wo im copyconstructor der fehler liegt, bzw. das gerade beim ersten alles richtig läuft und beim zweiten aufruf ein paar bits verschluckt werden,....</p>
</blockquote>
<p>Wie ich schon sagte:</p>
<p>Das delete im Copykonstruktor ist falsch.<br />
Der operator+ gibt eine Referenz auf eine lokale Variable zurück, die nach dem Aufruf nicht mehr existiert.</p>
<p>Das erzeugt <em>undefiniertes Verhalten</em>. Damit ist es müßig, sich darüber Gedanken zu machen, was das Programm tut, weil es alles tun könnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468661</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468661</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 05 Mar 2008 11:18:02 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 11:25:30 GMT]]></title><description><![CDATA[<p>ohhhhh man (eigene doooofheit),. super <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>
<p>ja,. funzt,.. danke leutz</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468668</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468668</guid><dc:creator><![CDATA[zeusosc]]></dc:creator><pubDate>Wed, 05 Mar 2008 11:25:30 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 11:29:00 GMT]]></title><description><![CDATA[<p>Wie MFK schon sagte, es gibt nicht altes zu löschen.<br />
Falls doch müsstest Du dann aber schon den delete[] nehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468672</guid><dc:creator><![CDATA[simon.gysi]]></dc:creator><pubDate>Wed, 05 Mar 2008 11:29:00 GMT</pubDate></item><item><title><![CDATA[Reply to copyconstructor baut misst on Wed, 05 Mar 2008 11:39:03 GMT]]></title><description><![CDATA[<blockquote>
<p>Int_t *my_ints = new Int_t[10];</p>
<p>...</p>
<p>delete []my_ints;</p>
<p>This tells the delete operator to go and find the array size, and delete all the objects.</p>
</blockquote>
<p>k,.. danke für den tipp <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="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1468689</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1468689</guid><dc:creator><![CDATA[zeusosc]]></dc:creator><pubDate>Wed, 05 Mar 2008 11:39:03 GMT</pubDate></item></channel></rss>