<?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[Funktionsweise Operatorüberladung?]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe mich mal versucht ein bischen in Operatorüberladung reinzuarbeiten..<br />
Ein kleines Test Programm:</p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;

class Zahl {
private:
    int Zahl;
public:
    void setZahl(int zahl) {
        Zahl = zahl;
    }

    int getZahl() {
        return Zahl;
    }

    const Zahl&amp; operator+(const Zahl &amp;z, const Zahl &amp;z2) {
        return z.getZahl()+z2.getZahl();
    }

};

int main(int argc, char** argv) {
    Zahl a, b, c;
    a.setZahl(2);
    b.setZahl(3);
    c = a+b; // -&gt; a.getZahl()+b.getZahl()
    cout &lt;&lt; c.getZahl();
    return (EXIT_SUCCESS);
}
</code></pre>
<p>Naja so in etwa sollte es doch funktionieren oder?<br />
3 Fehlermeldungen:<br />
main.cpp:18: error: ISO C++ forbids declaration of <code>Zahl' with no type main.cpp:18: error: expected</code>;' before &quot;operator&quot;<br />
main.cpp:23: error: expected `;' before '}' token</p>
<p>Und noch ne andere Frage: Was ist eine Elementfunktion und globale Funktion, und welche Unterschiede haben diese, die bei der Operatorüberladung eine Rolle spielen?</p>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/264707/funktionsweise-operatorüberladung</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Jul 2026 05:57:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/264707.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 11 Apr 2010 15:38:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktionsweise Operatorüberladung? on Sun, 11 Apr 2010 15:38:55 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe mich mal versucht ein bischen in Operatorüberladung reinzuarbeiten..<br />
Ein kleines Test Programm:</p>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;

class Zahl {
private:
    int Zahl;
public:
    void setZahl(int zahl) {
        Zahl = zahl;
    }

    int getZahl() {
        return Zahl;
    }

    const Zahl&amp; operator+(const Zahl &amp;z, const Zahl &amp;z2) {
        return z.getZahl()+z2.getZahl();
    }

};

int main(int argc, char** argv) {
    Zahl a, b, c;
    a.setZahl(2);
    b.setZahl(3);
    c = a+b; // -&gt; a.getZahl()+b.getZahl()
    cout &lt;&lt; c.getZahl();
    return (EXIT_SUCCESS);
}
</code></pre>
<p>Naja so in etwa sollte es doch funktionieren oder?<br />
3 Fehlermeldungen:<br />
main.cpp:18: error: ISO C++ forbids declaration of <code>Zahl' with no type main.cpp:18: error: expected</code>;' before &quot;operator&quot;<br />
main.cpp:23: error: expected `;' before '}' token</p>
<p>Und noch ne andere Frage: Was ist eine Elementfunktion und globale Funktion, und welche Unterschiede haben diese, die bei der Operatorüberladung eine Rolle spielen?</p>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1881121</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1881121</guid><dc:creator><![CDATA[Xeddon]]></dc:creator><pubDate>Sun, 11 Apr 2010 15:38:55 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsweise Operatorüberladung? on Sun, 11 Apr 2010 15:42:19 GMT]]></title><description><![CDATA[<p>1. Du deklarierst einen Member mit dem selbem Namen wie der Klasse<br />
2. Dein Operator returnet eine referenz auf eine lokale temporäre Variable<br />
3. Dein Operator ist nicht als const deklariert, obwohl du die Klasse nicht änderst<br />
4. Dein Operator ist kein Teil der Klasse sondern ein freier Operator. Der Operator als Teil der Klasse sieht so aus:</p>
<pre><code class="language-cpp">const Zahl(const Zahl&amp; obj) const
{
    return m_zahl + obj.m_zahl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1881124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1881124</guid><dc:creator><![CDATA[asdfasd]]></dc:creator><pubDate>Sun, 11 Apr 2010 15:42:19 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsweise Operatorüberladung? on Sun, 11 Apr 2010 15:43:15 GMT]]></title><description><![CDATA[<p>5. Deine getZahl Funktion ist auch nicht als const deklariert</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1881125</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1881125</guid><dc:creator><![CDATA[asdfasd]]></dc:creator><pubDate>Sun, 11 Apr 2010 15:43:15 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsweise Operatorüberladung? on Sun, 11 Apr 2010 15:43:20 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;

class Zahl {
private:
    int Zahl;
public:
    void setZahl(int zahl) {
        Zahl = zahl;
    }

    int getZahl() const{
        return Zahl;
    }

};
Zahl operator+(const Zahl &amp;z, const Zahl &amp;z2) {
		Zahl r;
		r.setZahl(z.getZahl()+z2.getZahl());
		return r;
}

int main(int argc, char** argv) {
    Zahl a, b, c;
    a.setZahl(2);
    b.setZahl(3);
    c = a+b; // -&gt; a.getZahl()+b.getZahl()
    std::cout &lt;&lt; c.getZahl() &lt;&lt; '\n';
    return EXIT_SUCCESS;
}
</code></pre>
<p>Hab ich Fehler weggemacht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1881127</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1881127</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 11 Apr 2010 15:43:20 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionsweise Operatorüberladung? on Sun, 11 Apr 2010 15:47:25 GMT]]></title><description><![CDATA[<p>Lies sonst auch mal den Artikel hier:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-232010.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-232010.html</a></p>
<p>Sollte deine Fragen so ziemlich alle beantworten können. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1881130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1881130</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 11 Apr 2010 15:47:25 GMT</pubDate></item></channel></rss>