<?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[falscher return value durch Methodenaufruf in Operatorüberladung]]></title><description><![CDATA[<p>Hallo, ich habe ein (für mich) sehr interessantes Problem.<br />
In einer Klasse zur &quot;verwaltung&quot; eines boolschen arrays, möchte ich die führenden Nullen killen. So habe ich folgende Methode:</p>
<pre><code class="language-cpp">void whole_number_type::clr_leading_zeros(void)
     {
     //first we have to check the most significant setted bit     
     cout&lt;&lt;endl&lt;&lt;&quot;input: &quot;;
     this-&gt;print();
     long int msb=0;
     for(long int i=0; i&lt;this-&gt;count;i++)
     {if(this-&gt;pBinary_array[i]){msb=i;}};
     if(msb!=(this-&gt;count-1))
     {
     bool *newArray; newArray=new bool[msb+1];
     for(long int i=0; i&lt;msb+1;i++)
     {newArray[i]=this-&gt;pBinary_array[i];};
     delete[] pBinary_array;
     this-&gt;count=msb+1;
     for(long int i=0; i&lt;count;i++)
     { this-&gt;pBinary_array[i]=newArray[i];};

     }    
     cout&lt;&lt;endl&lt;&lt;&quot;output:&quot;;
     this-&gt;print();
     }
</code></pre>
<p>rufe ich dies innerhalb einer anderen methode, z.b.: bei der operator überladung + auf (nicht aufregen, in der op-ü habe ich gleich die methode der summation mit reingebracht, daher...):</p>
<pre><code class="language-cpp">whole_number_type whole_number_type::operator+(const whole_number_type &amp;obj) const{
.
.
.

      cout&lt;&lt;endl&lt;&lt;&quot;temp b4 clr&quot;;
       temp.print();
       cout&lt;&lt;endl&lt;&lt;&quot;clr leading zeros&quot;;
       temp.clr_leading_zeros();
       cout&lt;&lt;endl&lt;&lt;&quot;temp array:&quot;;
       temp.print();
       return temp;
         };
</code></pre>
<p>kommt folgende ausgabe:</p>
<p>Konsole schrieb:</p>
<blockquote>
<p>temp b4 clr<br />
LSB: 0011000 :MSB<br />
clr leading zeros<br />
input:<br />
LSB: 0011000 :MSB<br />
output:<br />
LSB: 0011 :MSB<br />
temp array:<br />
LSB: 0011 :MSB<br />
= routine<br />
LSB: 0000 :MSB<br />
o=n+n:<br />
LSB: 0000 :MSB<br />
clr leading 0's of o:<br />
input:<br />
LSB: 0000 :MSB<br />
output:<br />
LSB: 0 :MSB<br />
o after clr:<br />
LSB: 0 :MSB</p>
</blockquote>
<p>o sollte dabei der temp value entsprechen.</p>
<p>o in der main:</p>
<pre><code class="language-cpp">int main(int argc, char *argv[]){
.
.
.
o=n+n;
cout&lt;&lt;endl&lt;&lt;&quot;o=n+n:&quot;;
o.print();
cout&lt;&lt;endl&lt;&lt;&quot;clr leading 0's of o:&quot;;
o.clr_leading_zeros();
cout&lt;&lt;endl&lt;&lt;&quot;o after clr:&quot;;
o.print();
cout&lt;&lt;endl;
system(&quot;PAUSE&quot;);
return EXIT_SUCCESS;
}
</code></pre>
<p>lasse ich das clr_leading_zeros in op+ weg bekomme ich folgende ausgabe:</p>
<p>Konsole schrieb:</p>
<blockquote>
<p>temp b4 clr<br />
LSB: 0011000 :MSB<br />
clr leading zeros<br />
temp array:<br />
LSB: 0011000 :MSB<br />
= routine<br />
LSB: 0011000 :MSB<br />
o=n+n:<br />
LSB: 0011000 :MSB<br />
clr leading 0's of o:<br />
input:<br />
LSB: 0011000 :MSB<br />
output:<br />
LSB: 0011 :MSB<br />
o after clr:<br />
LSB: 0011 :MSB</p>
</blockquote>
<p>und ich weiß nicht woran das liegt. Falls ich mich bzgl. des Problems falsch ausgedrückt haben sollte bitte nochmal nachfragen,..</p>
<p>gruß und dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/217579/falscher-return-value-durch-methodenaufruf-in-operatorüberladung</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 14:57:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/217579.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 08 Jul 2008 20:59:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to falscher return value durch Methodenaufruf in Operatorüberladung on Tue, 08 Jul 2008 20:59:31 GMT]]></title><description><![CDATA[<p>Hallo, ich habe ein (für mich) sehr interessantes Problem.<br />
In einer Klasse zur &quot;verwaltung&quot; eines boolschen arrays, möchte ich die führenden Nullen killen. So habe ich folgende Methode:</p>
<pre><code class="language-cpp">void whole_number_type::clr_leading_zeros(void)
     {
     //first we have to check the most significant setted bit     
     cout&lt;&lt;endl&lt;&lt;&quot;input: &quot;;
     this-&gt;print();
     long int msb=0;
     for(long int i=0; i&lt;this-&gt;count;i++)
     {if(this-&gt;pBinary_array[i]){msb=i;}};
     if(msb!=(this-&gt;count-1))
     {
     bool *newArray; newArray=new bool[msb+1];
     for(long int i=0; i&lt;msb+1;i++)
     {newArray[i]=this-&gt;pBinary_array[i];};
     delete[] pBinary_array;
     this-&gt;count=msb+1;
     for(long int i=0; i&lt;count;i++)
     { this-&gt;pBinary_array[i]=newArray[i];};

     }    
     cout&lt;&lt;endl&lt;&lt;&quot;output:&quot;;
     this-&gt;print();
     }
</code></pre>
<p>rufe ich dies innerhalb einer anderen methode, z.b.: bei der operator überladung + auf (nicht aufregen, in der op-ü habe ich gleich die methode der summation mit reingebracht, daher...):</p>
<pre><code class="language-cpp">whole_number_type whole_number_type::operator+(const whole_number_type &amp;obj) const{
.
.
.

      cout&lt;&lt;endl&lt;&lt;&quot;temp b4 clr&quot;;
       temp.print();
       cout&lt;&lt;endl&lt;&lt;&quot;clr leading zeros&quot;;
       temp.clr_leading_zeros();
       cout&lt;&lt;endl&lt;&lt;&quot;temp array:&quot;;
       temp.print();
       return temp;
         };
</code></pre>
<p>kommt folgende ausgabe:</p>
<p>Konsole schrieb:</p>
<blockquote>
<p>temp b4 clr<br />
LSB: 0011000 :MSB<br />
clr leading zeros<br />
input:<br />
LSB: 0011000 :MSB<br />
output:<br />
LSB: 0011 :MSB<br />
temp array:<br />
LSB: 0011 :MSB<br />
= routine<br />
LSB: 0000 :MSB<br />
o=n+n:<br />
LSB: 0000 :MSB<br />
clr leading 0's of o:<br />
input:<br />
LSB: 0000 :MSB<br />
output:<br />
LSB: 0 :MSB<br />
o after clr:<br />
LSB: 0 :MSB</p>
</blockquote>
<p>o sollte dabei der temp value entsprechen.</p>
<p>o in der main:</p>
<pre><code class="language-cpp">int main(int argc, char *argv[]){
.
.
.
o=n+n;
cout&lt;&lt;endl&lt;&lt;&quot;o=n+n:&quot;;
o.print();
cout&lt;&lt;endl&lt;&lt;&quot;clr leading 0's of o:&quot;;
o.clr_leading_zeros();
cout&lt;&lt;endl&lt;&lt;&quot;o after clr:&quot;;
o.print();
cout&lt;&lt;endl;
system(&quot;PAUSE&quot;);
return EXIT_SUCCESS;
}
</code></pre>
<p>lasse ich das clr_leading_zeros in op+ weg bekomme ich folgende ausgabe:</p>
<p>Konsole schrieb:</p>
<blockquote>
<p>temp b4 clr<br />
LSB: 0011000 :MSB<br />
clr leading zeros<br />
temp array:<br />
LSB: 0011000 :MSB<br />
= routine<br />
LSB: 0011000 :MSB<br />
o=n+n:<br />
LSB: 0011000 :MSB<br />
clr leading 0's of o:<br />
input:<br />
LSB: 0011000 :MSB<br />
output:<br />
LSB: 0011 :MSB<br />
o after clr:<br />
LSB: 0011 :MSB</p>
</blockquote>
<p>und ich weiß nicht woran das liegt. Falls ich mich bzgl. des Problems falsch ausgedrückt haben sollte bitte nochmal nachfragen,..</p>
<p>gruß und dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1543804</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1543804</guid><dc:creator><![CDATA[zeusosc]]></dc:creator><pubDate>Tue, 08 Jul 2008 20:59:31 GMT</pubDate></item><item><title><![CDATA[Reply to falscher return value durch Methodenaufruf in Operatorüberladung on Wed, 09 Jul 2008 07:04:09 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">//hier wirds geloescht...
     delete[] pBinary_array;
     this-&gt;count=msb+1;
     for(long int i=0; i&lt;count;i++)
     {
         //...und hier trotzdem benutzt
         this-&gt;pBinary_array[i]=newArray[i];
     };
</code></pre>
<p>Einfacher und richtig wäre:</p>
<pre><code class="language-cpp">pBinary_array = newArray;
</code></pre>
<p>PS: Rücke das nächste Mal bitte vernünftig ein. Den Kot zu lesen ist nicht so dolle.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1543896</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1543896</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Wed, 09 Jul 2008 07:04:09 GMT</pubDate></item><item><title><![CDATA[Reply to falscher return value durch Methodenaufruf in Operatorüberladung on Wed, 09 Jul 2008 12:36:33 GMT]]></title><description><![CDATA[<p>Jo,<br />
aua stimmt, habe</p>
<pre><code class="language-cpp">pBinary_array =new bool[msb+1];
</code></pre>
<p>vergessen.</p>
<p>war schon spät gestern.</p>
<p>danke nochmal</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1544210</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1544210</guid><dc:creator><![CDATA[zeusosc]]></dc:creator><pubDate>Wed, 09 Jul 2008 12:36:33 GMT</pubDate></item></channel></rss>