<?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[Operatoren Überladen]]></title><description><![CDATA[<p>Hallo erstmal, bin neu im Forum und habe eine Frage.</p>
<p>Es geht um das Überladen von Operatoren.<br />
Ich habe eine Klasse BigInt mit der sich beliebig große Zahlen speichern lassen.</p>
<p>Jetzt möchte ich diese natürlich auch noch addieren können und Überlade den + Operator. Die eigentlich Funktionsweise der Funktion ist dabei eigentlich klar.</p>
<p>Hier mal die Funktion:</p>
<pre><code>BigInt BigInt::operator+(BigInt &amp;BigInt2)
{
    int i;
    int sizeOfResult = 0, temp;
    int carry = 0;
    int sizeOfBigInt1 = size();
    int sizeOfBigInt2 = BigInt2.size();

    part *allPartsOfBigInt1[sizeOfBigInt1];
    part *allPartsOfBigInt2[sizeOfBigInt2];

    if (sizeOfBigInt1 &gt;= sizeOfBigInt2)
        sizeOfResult = sizeOfBigInt1;
    else
        sizeOfResult = sizeOfBigInt2;

    if ((allPartsOfBigInt1[sizeOfBigInt1]-&gt;ziffern + allPartsOfBigInt2[sizeOfBigInt2]-&gt;ziffern) &gt;= 1000000000)
        sizeOfResult++;

    BigInt result(sizeOfResult);

    for (i = 1; i &lt;= sizeOfResult; i++)
    {
        temp = allPartsOfBigInt1[i]-&gt;ziffern + allPartsOfBigInt2[i]-&gt;ziffern + carry;

        result.setPart(temp % 1000000000, i);

        carry = temp / 1000000000;
    }

    return result;
}
</code></pre>
<p>in meiner main sieht der Code so aus:</p>
<pre><code>...

    zahl1 = zahl2 + zahl3;

...
</code></pre>
<p>Aber ich bekomme einen Kompilerfehler:<br />
no match for Operator= in 'zahl1 = BigInt::Operator+(BigInt&amp;)(((BigInt&amp;)(&amp;zahl3)))</p>
<p>Mein = Operator ist schon Überladen und funktioniert, wenn ich schreibe: zahl1 = zahl.</p>
<p>Hier aber nochmal der Code:</p>
<pre><code>BigInt BigInt::operator=(BigInt &amp;copyNum)
{
    if (this == &amp;copyNum)
        return *this;

    destruct();

    int i, varSize;

    varSize = copyNum.size();

    part *allParts[varSize];
    part *workPart = zahlenteil;

    copyNum.returnAllParts(allParts);

    for (i = 1; i&lt;=varSize; i++)
    {
        *workPart = *allParts[i];

        if(i &lt; varSize)
        {
            workPart-&gt;next = new part;
            workPart = workPart-&gt;next;
        }

        workPart-&gt;next = NULL;
    }

    return *this;
}
</code></pre>
<p>Es wäre echt super, wenn mir jemand helfen könnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/286744/operatoren-überladen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 19:08:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/286744.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 15 May 2011 19:06:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Operatoren Überladen on Sun, 15 May 2011 19:06:58 GMT]]></title><description><![CDATA[<p>Hallo erstmal, bin neu im Forum und habe eine Frage.</p>
<p>Es geht um das Überladen von Operatoren.<br />
Ich habe eine Klasse BigInt mit der sich beliebig große Zahlen speichern lassen.</p>
<p>Jetzt möchte ich diese natürlich auch noch addieren können und Überlade den + Operator. Die eigentlich Funktionsweise der Funktion ist dabei eigentlich klar.</p>
<p>Hier mal die Funktion:</p>
<pre><code>BigInt BigInt::operator+(BigInt &amp;BigInt2)
{
    int i;
    int sizeOfResult = 0, temp;
    int carry = 0;
    int sizeOfBigInt1 = size();
    int sizeOfBigInt2 = BigInt2.size();

    part *allPartsOfBigInt1[sizeOfBigInt1];
    part *allPartsOfBigInt2[sizeOfBigInt2];

    if (sizeOfBigInt1 &gt;= sizeOfBigInt2)
        sizeOfResult = sizeOfBigInt1;
    else
        sizeOfResult = sizeOfBigInt2;

    if ((allPartsOfBigInt1[sizeOfBigInt1]-&gt;ziffern + allPartsOfBigInt2[sizeOfBigInt2]-&gt;ziffern) &gt;= 1000000000)
        sizeOfResult++;

    BigInt result(sizeOfResult);

    for (i = 1; i &lt;= sizeOfResult; i++)
    {
        temp = allPartsOfBigInt1[i]-&gt;ziffern + allPartsOfBigInt2[i]-&gt;ziffern + carry;

        result.setPart(temp % 1000000000, i);

        carry = temp / 1000000000;
    }

    return result;
}
</code></pre>
<p>in meiner main sieht der Code so aus:</p>
<pre><code>...

    zahl1 = zahl2 + zahl3;

...
</code></pre>
<p>Aber ich bekomme einen Kompilerfehler:<br />
no match for Operator= in 'zahl1 = BigInt::Operator+(BigInt&amp;)(((BigInt&amp;)(&amp;zahl3)))</p>
<p>Mein = Operator ist schon Überladen und funktioniert, wenn ich schreibe: zahl1 = zahl.</p>
<p>Hier aber nochmal der Code:</p>
<pre><code>BigInt BigInt::operator=(BigInt &amp;copyNum)
{
    if (this == &amp;copyNum)
        return *this;

    destruct();

    int i, varSize;

    varSize = copyNum.size();

    part *allParts[varSize];
    part *workPart = zahlenteil;

    copyNum.returnAllParts(allParts);

    for (i = 1; i&lt;=varSize; i++)
    {
        *workPart = *allParts[i];

        if(i &lt; varSize)
        {
            workPart-&gt;next = new part;
            workPart = workPart-&gt;next;
        }

        workPart-&gt;next = NULL;
    }

    return *this;
}
</code></pre>
<p>Es wäre echt super, wenn mir jemand helfen könnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2063783</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2063783</guid><dc:creator><![CDATA[Super-Ing]]></dc:creator><pubDate>Sun, 15 May 2011 19:06:58 GMT</pubDate></item><item><title><![CDATA[Reply to Operatoren Überladen on Sun, 15 May 2011 19:13:02 GMT]]></title><description><![CDATA[<p>Dein operator+ liefert eine temporäre Variable, die kannst du nicht an eine nicht-konstante Referenz binden. Da du sowieso nicht vorhast, sie zu ändern, solltest du die Parameter der beiden Operatoren als <code>const BigInt&amp;</code> definieren.</p>
<p>(und op+ definierst du lieber als globale Funktion, dann klappen auch Ausdrücke wie &quot;2+zahl&quot;)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2063790</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2063790</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sun, 15 May 2011 19:13:02 GMT</pubDate></item><item><title><![CDATA[Reply to Operatoren Überladen on Sun, 15 May 2011 19:13:08 GMT]]></title><description><![CDATA[<p>Mach mal die Referenzen <code>const</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2063791</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2063791</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 15 May 2011 19:13:08 GMT</pubDate></item><item><title><![CDATA[Reply to Operatoren Überladen on Sun, 15 May 2011 19:22:55 GMT]]></title><description><![CDATA[<p>Ich habe die Referenzen als const bezeichnet, aber immernoch selber Fehler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2063797</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2063797</guid><dc:creator><![CDATA[Super-Ing]]></dc:creator><pubDate>Sun, 15 May 2011 19:22:55 GMT</pubDate></item><item><title><![CDATA[Reply to Operatoren Überladen on Sun, 15 May 2011 19:37:43 GMT]]></title><description><![CDATA[<p>Mach den <code>operator+</code> wie schon vorgeschlagen global.</p>
<pre><code class="language-cpp">BigInt operator+ (const BigInt&amp; lhs, const BigInt&amp; rhs);
</code></pre>
<p>Zeig dann den neuen Code, aber auf ein Minimum reduziert. Lasse alles Irrelevante weg, aber so, dass der ursprüngliche Fehler immer noch reproduzierbar ist. Verwende ausserdem bitte [cpp]-Tags und nicht [code]-Tags.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2063813</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2063813</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 15 May 2011 19:37:43 GMT</pubDate></item><item><title><![CDATA[Reply to Operatoren Überladen on Sun, 15 May 2011 19:54:02 GMT]]></title><description><![CDATA[<p>Jetzt hat er es doch geschluckt, danke euch mal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2063824</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2063824</guid><dc:creator><![CDATA[Super-Ing]]></dc:creator><pubDate>Sun, 15 May 2011 19:54:02 GMT</pubDate></item><item><title><![CDATA[Reply to Operatoren Überladen on Mon, 16 May 2011 09:48:54 GMT]]></title><description><![CDATA[<p>Und wenn dein Compiler C++0x kann, kannst du beim Rückgabewert die Move Semantics nutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2063944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2063944</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Mon, 16 May 2011 09:48:54 GMT</pubDate></item><item><title><![CDATA[Reply to Operatoren Überladen on Mon, 16 May 2011 14:20:04 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Und wenn dein Compiler C++0x kann, kannst du beim Rückgabewert die Move Semantics nutzen.</p>
</blockquote>
<p>Sollte nicht nötig sein. Falls der Typ einen Move-Konstruktor bereitstellt (und das tut er, sofern die Grossen Drei nicht selbst implementiert werden), wird dieser nach Möglichkeit automatisch verwendet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2064088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2064088</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 16 May 2011 14:20:04 GMT</pubDate></item></channel></rss>