<?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[Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST]]></title><description><![CDATA[<p>Ich möchte gerne abfragen, ob von einer Klasse eine (bestimmte) Instanz existiert.<br />
Beispiel:</p>
<pre><code class="language-cpp">class foo {...};

int main()
{
 foo test;
 if (test)
 {...}
else {}
}
</code></pre>
<p>Wäre das richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/302839/abfrage-ob-von-einer-klasse-eine-bestimmte-instanz-existiert-gelöst</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 03:12:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/302839.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 28 Apr 2012 14:53:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sun, 29 Apr 2012 21:42:50 GMT]]></title><description><![CDATA[<p>Ich möchte gerne abfragen, ob von einer Klasse eine (bestimmte) Instanz existiert.<br />
Beispiel:</p>
<pre><code class="language-cpp">class foo {...};

int main()
{
 foo test;
 if (test)
 {...}
else {}
}
</code></pre>
<p>Wäre das richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206388</guid><dc:creator><![CDATA[redrew99]]></dc:creator><pubDate>Sun, 29 Apr 2012 21:42:50 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 14:56:35 GMT]]></title><description><![CDATA[<p>Hä? Wie soll die Instanz denn nicht existieren, du hast sie doch eine Zeile vorher erstellt. (Und die if Abfrage macht natürlich was anderes.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206390</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 28 Apr 2012 14:56:35 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 15:07:08 GMT]]></title><description><![CDATA[<p>Ich glaube er will wissen, ob generell eine Instanz der Klasse existiert.</p>
<p>Wenn ja, weiß ich nicht, wie das geht!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206397</guid><dc:creator><![CDATA[Die erinnerung]]></dc:creator><pubDate>Sat, 28 Apr 2012 15:07:08 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 15:11:33 GMT]]></title><description><![CDATA[<p>Er schreibt doch sogar extra &quot;(bestimmte)&quot;, also das glaube ich eher nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206402</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 28 Apr 2012 15:11:33 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 15:14:47 GMT]]></title><description><![CDATA[<p>Ein prima Verwendungszweck von <code>static</code> :</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class X
{
public:
    static int anzahl_instanzen;
    X() { ++anzahl_instanzen; }
    ~X() { --anzahl_instanzen; }
};

int X::anzahl_instanzen = 0;

int main()
{
    {
        X x;
        std::cout &lt;&lt; X::anzahl_instanzen &lt;&lt; &quot;\n&quot;; //1
    }
    if(X::anzahl_instanzen == 0)
        std::cout &lt;&lt; &quot;Keine Instanz mehr da.&quot;;
}
</code></pre>
<p>EDIT: Also das bestimmte steht ja in Klammern. Ansonsten kann er ja gucken, welchen Wert anzahl_instanzen hat. Da kann man sich ja auch was von ableiten.<br />
Was das jetzt soll, keine Ahnung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206403</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206403</guid><dc:creator><![CDATA[Incocnito]]></dc:creator><pubDate>Sat, 28 Apr 2012 15:14:47 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 15:17:47 GMT]]></title><description><![CDATA[<p>Incocnito schrieb:</p>
<blockquote>
<p>Ein prima Verwendungszweck von <code>static</code></p>
</blockquote>
<p>Wohl eher ein prima Antipattern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206408</guid><dc:creator><![CDATA[kognitivtroll]]></dc:creator><pubDate>Sat, 28 Apr 2012 15:17:47 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 15:36:21 GMT]]></title><description><![CDATA[<p>Incocnito schrieb:</p>
<blockquote>
<p>Ein prima Verwendungszweck von <code>static</code> :</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class X
{
public:
    static int anzahl_instanzen;
    X() { ++anzahl_instanzen; }
    ~X() { --anzahl_instanzen; }
};

int X::anzahl_instanzen = 0;

int main()
{
    {
        X x;
        std::cout &lt;&lt; X::anzahl_instanzen &lt;&lt; &quot;\n&quot;; //1
    }
    if(X::anzahl_instanzen == 0)
        std::cout &lt;&lt; &quot;Keine Instanz mehr da.&quot;;
}
</code></pre>
<p>EDIT: Also das bestimmte steht ja in Klammern. Ansonsten kann er ja gucken, welchen Wert anzahl_instanzen hat. Da kann man sich ja auch was von ableiten.<br />
Was das jetzt soll, keine Ahnung.</p>
</blockquote>
<p>Danke soweit.<br />
Eigentlich reicht die Abfrage einer bestimmten namentlich bekannten Instanz,<br />
beim Schreiben war mir nur aufgefallen, daß es eigentlich ja auch ohne Kenntnis<br />
des Namens gehen müßte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206412</guid><dc:creator><![CDATA[redrew99]]></dc:creator><pubDate>Sat, 28 Apr 2012 15:36:21 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 15:32:53 GMT]]></title><description><![CDATA[<p>redrew99 schrieb:</p>
<blockquote>
<p>Aber die Abfrage einer namentlich bekannten Instanz reicht mir schon.</p>
</blockquote>
<p>Wie soll denn bitte eine Instanz namentlich bekannt sein aber nicht existieren? Du bist echt lustig. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206413</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206413</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 28 Apr 2012 15:32:53 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 15:43:38 GMT]]></title><description><![CDATA[<p>Naja, wenn eine Instanz je nach Bedingung mit Daten gefüllt oder zerstört werden soll oder nicht, ist eine solche Abfrage notwendig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206417</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206417</guid><dc:creator><![CDATA[redrew99]]></dc:creator><pubDate>Sat, 28 Apr 2012 15:43:38 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 15:41:31 GMT]]></title><description><![CDATA[<p>Nein verdammt. Bastel mal ein sinnvolles Beispiel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206420</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206420</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 28 Apr 2012 15:41:31 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 15:41:31 GMT]]></title><description><![CDATA[<p>redrew99 schrieb:</p>
<blockquote>
<p>Naja, wenn bei Schleifendurchläufen eine Instanz unter bestimmten Voraussetzungen gelöscht bzw. neu erzeugt werden soll, braucht man eine Abfrage ob die Instanz bereits existiert.</p>
</blockquote>
<p>Da fehlt es aber noch gewaltig an den Grundlagen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206419</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206419</guid><dc:creator><![CDATA[ohje]]></dc:creator><pubDate>Sat, 28 Apr 2012 15:41:31 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sat, 28 Apr 2012 15:42:15 GMT]]></title><description><![CDATA[<p>redrew99 schrieb:</p>
<blockquote>
<p>Naja, wenn bei Schleifendurchläufen eine Instanz unter bestimmten Voraussetzungen gelöscht bzw. neu erzeugt werden soll, braucht man eine Abfrage ob die Instanz bereits existiert.</p>
</blockquote>
<p>Kannst du das an einem Code näher erläutern? Ich habe irgendwie das Gefühl, dass dein Beispielcode ein <code>new</code> beinhalten wird, kann das sein?</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206421</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206421</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Sat, 28 Apr 2012 15:42:15 GMT</pubDate></item><item><title><![CDATA[Reply to Abfrage, ob von einer Klasse eine bestimmte Instanz existiert GELÖST on Sun, 29 Apr 2012 21:42:29 GMT]]></title><description><![CDATA[<p>Problem hat sich erledigt, danke für die Hilfe soweit.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2206424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2206424</guid><dc:creator><![CDATA[redrew99]]></dc:creator><pubDate>Sun, 29 Apr 2012 21:42:29 GMT</pubDate></item></channel></rss>