<?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[statische const Funktion]]></title><description><![CDATA[<p>Hallo,</p>
<p>ist es nicht möglich eine statische Funktion zu schreiben, die ein<br />
konstantes Objekt zurückliefert?</p>
<p>Also so etwa:</p>
<pre><code class="language-cpp">static MyObj&amp; getObj() const;
</code></pre>
<p>Hier krieg ich nämlich nen Compiler-Fehler, der mir das const verbietet.<br />
Ohne geht es dann...</p>
<p>Gibt es ne andere Möglichkeit?</p>
<p>Gruß,<br />
Manuel</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/167952/statische-const-funktion</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 04:10:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/167952.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 17 Dec 2006 01:53:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to statische const Funktion on Sun, 17 Dec 2006 01:53:50 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ist es nicht möglich eine statische Funktion zu schreiben, die ein<br />
konstantes Objekt zurückliefert?</p>
<p>Also so etwa:</p>
<pre><code class="language-cpp">static MyObj&amp; getObj() const;
</code></pre>
<p>Hier krieg ich nämlich nen Compiler-Fehler, der mir das const verbietet.<br />
Ohne geht es dann...</p>
<p>Gibt es ne andere Möglichkeit?</p>
<p>Gruß,<br />
Manuel</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1193196</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193196</guid><dc:creator><![CDATA[Manuel27]]></dc:creator><pubDate>Sun, 17 Dec 2006 01:53:50 GMT</pubDate></item><item><title><![CDATA[Reply to statische const Funktion on Sun, 17 Dec 2006 02:05:35 GMT]]></title><description><![CDATA[<p>Hm .. ich verstehe nicht ganz, wieso du das brauchst.<br />
Ich nehme an, die Funktion ist Teil einer Klasse - also eine Methode.<br />
static Methoden sind nicht Objektgebunden, damit meine ich, dass sie sich nicht auf eine konkrete Instanz der Klasse beziehen. Dadurch können sie keine nicht-static Elemente der Klasse lesen oder gar schreiben.<br />
Eine const Methode zeichnet sich dadurch aus, dass sie keine Elemente (Member) der Klasse verändern kann / darf. Sie bezieht sich aber sehr wohl auf eine konkrete Instanz der Klasse - denn das Lesen von Elementen ist wohl möglich.<br />
Von daher schließt die static foobar() const; deklaration einander aus.</p>
<p>Ich denke du meintest etwas der Art: static const MyObj&amp; getObj();<br />
Damit gibst du eine const-Referenz auf ein MyObj zurück.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1193199</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193199</guid><dc:creator><![CDATA[_dennis]]></dc:creator><pubDate>Sun, 17 Dec 2006 02:05:35 GMT</pubDate></item><item><title><![CDATA[Reply to statische const Funktion on Sun, 17 Dec 2006 03:43:33 GMT]]></title><description><![CDATA[<p>Danke Dennis...</p>
<p>Bor, bin ich blöd...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1193205</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193205</guid><dc:creator><![CDATA[Manuel27]]></dc:creator><pubDate>Sun, 17 Dec 2006 03:43:33 GMT</pubDate></item><item><title><![CDATA[Reply to statische const Funktion on Sun, 17 Dec 2006 04:06:53 GMT]]></title><description><![CDATA[<p>Klar kann eine statische Methode ein konstantes Objekt zurückliefern.</p>
<pre><code class="language-cpp">class foo
{
public:
    static foo const bar()
    {
        return foo();
    }

    static foo const&amp; baz()
    {
        static foo f = foo();
        return f;
    }
};
</code></pre>
<p><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/1193207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1193207</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 17 Dec 2006 04:06:53 GMT</pubDate></item></channel></rss>