<?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[Probleme mit static und member functions]]></title><description><![CDATA[<p>Hey @all,</p>
<p>ich habe eine static member function sowie eine normale member function</p>
<pre><code class="language-cpp">static void updateObjects();
void dumpMemory();
</code></pre>
<p>Nun würde ich gerne von &quot;updateObjects();&quot; die Funktion dumpMemory aufrufen.<br />
wenn ich in updateObjects den this pointer verwende passiert genau das was es machen sollen, nämlich:</p>
<pre><code>error: `this' is unavailable for static member functions
</code></pre>
<p>ohne den &quot;this&quot; Pointer erhalte ich</p>
<pre><code>error: cannot call member function `void MyClass::dumpMemory()' without object
</code></pre>
<p>in dumpMemory(); wird zudem auch auf Variablen der Klasse zugegriffen.<br />
Wie kann ich innerhalb von &quot;updateObjects&quot; die funktion &quot;dumpMemory&quot; aufrufen?</p>
<p>Lg _freeze_</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/215454/probleme-mit-static-und-member-functions</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 07:53:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/215454.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 Jun 2008 09:55:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit static und member functions on Wed, 11 Jun 2008 09:55:27 GMT]]></title><description><![CDATA[<p>Hey @all,</p>
<p>ich habe eine static member function sowie eine normale member function</p>
<pre><code class="language-cpp">static void updateObjects();
void dumpMemory();
</code></pre>
<p>Nun würde ich gerne von &quot;updateObjects();&quot; die Funktion dumpMemory aufrufen.<br />
wenn ich in updateObjects den this pointer verwende passiert genau das was es machen sollen, nämlich:</p>
<pre><code>error: `this' is unavailable for static member functions
</code></pre>
<p>ohne den &quot;this&quot; Pointer erhalte ich</p>
<pre><code>error: cannot call member function `void MyClass::dumpMemory()' without object
</code></pre>
<p>in dumpMemory(); wird zudem auch auf Variablen der Klasse zugegriffen.<br />
Wie kann ich innerhalb von &quot;updateObjects&quot; die funktion &quot;dumpMemory&quot; aufrufen?</p>
<p>Lg _freeze_</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1526879</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1526879</guid><dc:creator><![CDATA[_freeze_]]></dc:creator><pubDate>Wed, 11 Jun 2008 09:55:27 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit static und member functions on Wed, 11 Jun 2008 10:08:41 GMT]]></title><description><![CDATA[<p>So z.B. Aber wozu soll das gut sein?</p>
<pre><code class="language-cpp">void XY::updateObjects(XY&amp; obj)
    {
        obj.dumpMemory();
    }

    //...
    XY a;
    XY::updateObjects(a);
</code></pre>
<p>static Methoden haben keinen this-Zeiger, weil sie ja eben nicht an konkrete Objekte gebunden sind. Wenn Du eine Methode für ein konkretes Objekt aufrufen willst, solltest Du auch Membermethoden benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1526889</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1526889</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Wed, 11 Jun 2008 10:08:41 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit static und member functions on Wed, 11 Jun 2008 10:07:08 GMT]]></title><description><![CDATA[<p><em>freeze</em> schrieb:</p>
<blockquote>
<p>Nun würde ich gerne von &quot;updateObjects();&quot; die Funktion dumpMemory aufrufen.</p>
</blockquote>
<p>Von welchem Objekt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1526890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1526890</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 11 Jun 2008 10:07:08 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit static und member functions on Wed, 11 Jun 2008 10:08:53 GMT]]></title><description><![CDATA[<p>Die static Methode gehört zur Klasse und somit zu keinem Objekt. Während die nicht-static Methode zu einem Objekt gehört. Dadurch kannst du nicht aus einer static Methode eine Methode eines Objektes aufrufen, ausser du machst etwas in der Art:</p>
<pre><code class="language-cpp">class CFoo
{
    static update(CFoo&amp; rFoo) { rFoo.dump(); };

    void dump() { /* whatever */ };
}
</code></pre>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1526891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1526891</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Wed, 11 Jun 2008 10:08:53 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit static und member functions on Wed, 11 Jun 2008 11:00:14 GMT]]></title><description><![CDATA[<p>Vielen Dank für die schnellen Antworten, hat prima funktioniert</p>
<p>Lg _freeze_</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1526927</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1526927</guid><dc:creator><![CDATA[_freeze_]]></dc:creator><pubDate>Wed, 11 Jun 2008 11:00:14 GMT</pubDate></item></channel></rss>