<?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[Wie erste Instanz markieren]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich brauche in einer Klasse eine Sonderbehandlung für die 1. Instanz. Ich will da zu ein Flag benutzen:</p>
<pre><code class="language-cpp">class Foo {
private:
   bool isFirstInstance;

};
</code></pre>
<p>Wie mach ich das, dass isFirstInstance nur für die 1. Instanz true ist, für alle weiteren false? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/288258/wie-erste-instanz-markieren</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 01:27:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/288258.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 13 Jun 2011 13:42:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 13:42:08 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich brauche in einer Klasse eine Sonderbehandlung für die 1. Instanz. Ich will da zu ein Flag benutzen:</p>
<pre><code class="language-cpp">class Foo {
private:
   bool isFirstInstance;

};
</code></pre>
<p>Wie mach ich das, dass isFirstInstance nur für die 1. Instanz true ist, für alle weiteren false? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077461</guid><dc:creator><![CDATA[Markierer]]></dc:creator><pubDate>Mon, 13 Jun 2011 13:42:08 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 13:46:41 GMT]]></title><description><![CDATA[<p>Mit dem Schlüsselwort static kannst du Variablen haben, die sich auf alle Instanzen einer Klasse beziehen, z.B. so:</p>
<pre><code class="language-cpp">class Foo {
private:
 static bool isFirstInstance;
public:
 Foo()
  {
    if (isFirstInstance) // ...

    isFirstInstance = false;
  }
}; 	

bool Foo::isFirstInstance = true;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2077465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077465</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 13 Jun 2011 13:46:41 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 13:55:15 GMT]]></title><description><![CDATA[<p>@Markierer: Dein Code klappt nicht, weil da immer ALLE Instanzen den selben Wert haben.</p>
<p>Geht das hier?</p>
<pre><code class="language-cpp">Foo::Foo() {
  static bool isFirstWindow = true;
  if(isFirstWindow) {
	mIsFirstWindow = true;
	isFirstWindow = false;
   }
}
</code></pre>
<p>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077470</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077470</guid><dc:creator><![CDATA[Markierer]]></dc:creator><pubDate>Mon, 13 Jun 2011 13:55:15 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 14:15:56 GMT]]></title><description><![CDATA[<p>Alternativ so hier:</p>
<pre><code class="language-cpp">class Foo
{
  static std::size_t id;
  std::size_t my_id;
public:
  Foo() : my_id(id)
  { id++;}

  bool isFirstInstance() const
  { return !my_id; }
};

Foo::id = 0;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2077487</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077487</guid><dc:creator><![CDATA[bmario]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:15:56 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 14:22:47 GMT]]></title><description><![CDATA[<p>Markierer schrieb:</p>
<blockquote>
<p>Ich brauche in einer Klasse eine Sonderbehandlung für die 1. Instanz.</p>
</blockquote>
<p>Wofür?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077494</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077494</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:22:47 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 14:28:13 GMT]]></title><description><![CDATA[<p>dot schrieb:</p>
<blockquote>
<p>Markierer schrieb:</p>
<blockquote>
<p>Ich brauche in einer Klasse eine Sonderbehandlung für die 1. Instanz.</p>
</blockquote>
<p>Wofür?</p>
</blockquote>
<p>Gibst du eigentlich auch mal konkrete Tipps oder immer nur Meta Fragen? <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>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/25467">@bmario</a>: Ich sehe da keinen Vorteil gegenüber meinem Ansatz. Bei dir habe ich in der Klasse einen Member mehr (id), den ich eigentlich gar nicht brauche.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077499</guid><dc:creator><![CDATA[Markierer]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:28:13 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 14:31:13 GMT]]></title><description><![CDATA[<p>Markierer schrieb:</p>
<blockquote>
<p>dot schrieb:</p>
<blockquote>
<p>Markierer schrieb:</p>
<blockquote>
<p>Ich brauche in einer Klasse eine Sonderbehandlung für die 1. Instanz.</p>
</blockquote>
<p>Wofür?</p>
</blockquote>
<p>Gibst du eigentlich auch mal konkrete Tipps oder immer nur Meta Fragen? <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>
</blockquote>
<p>Das ist aber eine sehr gute Frage, du solltest sie beantworten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077502</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077502</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:31:13 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 14:40:44 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Markierer schrieb:</p>
<blockquote>
<p>dot schrieb:</p>
<blockquote>
<p>Markierer schrieb:</p>
<blockquote>
<p>Ich brauche in einer Klasse eine Sonderbehandlung für die 1. Instanz.</p>
</blockquote>
<p>Wofür?</p>
</blockquote>
<p>Gibst du eigentlich auch mal konkrete Tipps oder immer nur Meta Fragen? <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>
</blockquote>
<p>Das ist aber eine sehr gute Frage, du solltest sie beantworten.</p>
</blockquote>
<p>Das 1. Objekt ist eben ein Spezialfall. Hat technische Gründe und tut hier nichts zur Sache. <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>
<p>Ist dir aufgefallen, dass dein Ansatz falsch ist SeppJ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077508</guid><dc:creator><![CDATA[Markierer]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:40:44 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 14:45:14 GMT]]></title><description><![CDATA[<p>Markierer schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<p>Markierer schrieb:</p>
<blockquote>
<p>dot schrieb:</p>
<blockquote>
<p>Markierer schrieb:</p>
<blockquote>
<p>Ich brauche in einer Klasse eine Sonderbehandlung für die 1. Instanz.</p>
</blockquote>
<p>Wofür?</p>
</blockquote>
<p>Gibst du eigentlich auch mal konkrete Tipps oder immer nur Meta Fragen? <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>
</blockquote>
<p>Das ist aber eine sehr gute Frage, du solltest sie beantworten.</p>
</blockquote>
<p>Das 1. Objekt ist eben ein Spezialfall. Hat technische Gründe und tut hier nichts zur Sache. <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>
</blockquote>
<p>Dann behalt das lieber für dich, sonst könnte dir noch jemand helfen.</p>
<blockquote>
<p>Ist dir aufgefallen, dass dein Ansatz falsch ist SeppJ?</p>
</blockquote>
<p>Nein, denn er ist richtig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077511</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:45:14 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 14:47:14 GMT]]></title><description><![CDATA[<p>Markierer schrieb:</p>
<blockquote>
<p>Das 1. Objekt ist eben ein Spezialfall. Hat technische Gründe und tut hier nichts zur Sache. <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>
</blockquote>
<p>Doch, tut schon was zur Sache. Weil sowas eine recht komische Semantik hat und schnell mal zu mühsamen Fehlern führen kann. Was soll passieren, wenn das Objekt kopiert oder zugewiesen wird? Ist das Erste-Instanz-Flag wirklich Bestandteil des Objektstatus, oder geht es mehr darum, bei der ersten Benutzung etwas zu laden o.Ä.? Dann würde ich nämlich keine nicht-statische Membervariable verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077513</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077513</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:47:14 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 14:51:57 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<blockquote>
<p>Ist dir aufgefallen, dass dein Ansatz falsch ist SeppJ?</p>
</blockquote>
<p>Nein, denn er ist richtig.</p>
</blockquote>
<p>Nein, er ist Schwachsinn. Ab der 2. Instanz ist das Flag IMMER falsch.</p>
<p>Was soll immer dieses blöde Meta Gebrabbel hier? Die Gründe liegen hier in eine externen Lib und tun hier einen Scheiß zur Sache.</p>
<p>Bis jetzt kam genau eine brauchbare Antwort und zwar bmario.</p>
<p><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/2077519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077519</guid><dc:creator><![CDATA[Markierer]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:51:57 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 14:56:03 GMT]]></title><description><![CDATA[<p>Markierer schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<blockquote>
<p>Ist dir aufgefallen, dass dein Ansatz falsch ist SeppJ?</p>
</blockquote>
<p>Nein, denn er ist richtig.</p>
</blockquote>
<p>Nein, er ist Schwachsinn. Ab der 2. Instanz ist das Flag IMMER falsch.</p>
</blockquote>
<p>Häh? Du wolltest doch etwas, dass die erste Instanz markiert. Deshalb ist es nur bei der ersten Instanz wahr. Und überdenk mal deinen Ton. Wenn du freiwillige Helfer nur anpöbelst und auf Rückfragen nur noch mehr pöbelst, willst du offensichtlich keine Hilfe und der Thread kann geschlossen werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077523</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 13 Jun 2011 14:56:03 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 15:18:25 GMT]]></title><description><![CDATA[<p>Markierer schrieb:</p>
<blockquote>
<p>Gibst du eigentlich auch mal konkrete Tipps oder immer nur Meta Fragen?</p>
</blockquote>
<p>Ja. Allerdings versuch ich mich (soweit es mir möglich ist) auf <em>gute</em> Tips zu beschränken. Und auf deine Frage kann ich mangels Information leider keinen besseren Tip geben als: Du läufst gerade in ein Minenfeld, bleib besser sofort stehen wo du bist und rühr dich nicht vom Fleck, sag uns wo du hinwolltest und wir können dir einen sicheren Weg zeigen.</p>
<p>Aber gut, wenn du den Sinn von &quot;Metagebrabbel&quot; nicht begreifen willst und zu einer Diskussion über die Sinnhaftigkeit deines Ansatzes nicht bereit bist (am Ende könntest du ja noch was lernen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> ) dann sollst du auch einfach nur haben um was du gebeten hast:</p>
<pre><code class="language-cpp">class Foo
{
private: 
  static Foo* firstInstance;
public: 
  Foo() 
  { 
    if (firstInstance == 0)
      firstInstance = this;
  } 
};

// Foo.cpp
Foo* Foo::firstInstance = 0;
</code></pre>
<p>Viel Spaß noch damit, du wirsts schon auch noch lernen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /> Tip: Wenn dir mal fad ist kannst du dir ja anschauen wofür man Klassen in echt so verwendet...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077524</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077524</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Mon, 13 Jun 2011 15:18:25 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 15:06:30 GMT]]></title><description><![CDATA[<p>Markierer schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<blockquote>
<p>Ist dir aufgefallen, dass dein Ansatz falsch ist SeppJ?</p>
</blockquote>
<p>Nein, denn er ist richtig.</p>
</blockquote>
<p>Nein, er ist Schwachsinn. Ab der 2. Instanz ist das Flag IMMER falsch.</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> Rat mal warum das so sein sollte!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077527</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077527</guid><dc:creator><![CDATA[inter2k3]]></dc:creator><pubDate>Mon, 13 Jun 2011 15:06:30 GMT</pubDate></item><item><title><![CDATA[Reply to Wie erste Instanz markieren on Mon, 13 Jun 2011 15:31:26 GMT]]></title><description><![CDATA[<p>Auf das blabla von dot brauch ich ja nicht eingehen. Ist eh nur das übliche &quot;Dein Design ist Kacke. Ich weiß alles besser.&quot; Obwohl er NULL Ahnung vom Gesamtproblem hat. Grandios solche Leute.</p>
<p>inter2k3 schrieb:</p>
<blockquote>
<p>Markierer schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<blockquote>
<p>Ist dir aufgefallen, dass dein Ansatz falsch ist SeppJ?</p>
</blockquote>
<p>Nein, denn er ist richtig.</p>
</blockquote>
<p>Nein, er ist Schwachsinn. Ab der 2. Instanz ist das Flag IMMER falsch.</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> Rat mal warum das so sein sollte!</p>
</blockquote>
<p>Bei EINER statischen Variable für alle Instanzen ist es völlig unmöglich die 1. Instanz zu erkennen. Ergo ist sein Code totaler Müll.</p>
<p>Ich benutzt jetzt meinen Code mit der lokalen statischen Variable. Danke für Nichts!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2077538</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2077538</guid><dc:creator><![CDATA[Markierer]]></dc:creator><pubDate>Mon, 13 Jun 2011 15:31:26 GMT</pubDate></item></channel></rss>