<?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[std::map - wird Instanz automatisch erstellt?]]></title><description><![CDATA[<p>Hallo!<br />
Mal eine kleine, aber feine Frage: Wird eine Instanz, die in std::map noch nicht vorhanden ist, automatisch erstellt, so, dass folgendes immer funktioniert?</p>
<pre><code class="language-cpp">class Test
{
public:
    void AddToMap(std::string Key, std::string Value)
    {
        // existier solch ein Eintrag bereits?
        std::map&lt;std::string, std::list&lt;std::string&gt; &gt;::iterator it = this-&gt;m_Map.find(Key);

        if (it != this-&gt;m_Map.end())
        {
            for (std::list&lt;std::string&gt;::iterator it2 = it-&gt;second.begin(); it2 != it-&gt;second.end(); ++it2)
            {
                if ((*it2) == Key)
                {
                    // ist bereits vorhanden
                    return;
                }
            }
        }

        // an dieser Stelle kann es nun sein, dass Key noch nicht in m_Map vorhanden ist
        // geht das hier trotzdem?
        this-&gt;m_Map[Key].push_back(Value);
        // wie man sieht, wird gleich die push_back-Funktion von std::list aufgerufen, obwohl ich selber keine Instanz erstellt habe
    }

private:
    std::map&lt;std::string, std::list&lt;std::string&gt; &gt; m_Map;
};
</code></pre>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/278032/std-map-wird-instanz-automatisch-erstellt</link><generator>RSS for Node</generator><lastBuildDate>Tue, 25 Aug 2026 12:44:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/278032.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 28 Nov 2010 19:39:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Sun, 28 Nov 2010 19:39:06 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Mal eine kleine, aber feine Frage: Wird eine Instanz, die in std::map noch nicht vorhanden ist, automatisch erstellt, so, dass folgendes immer funktioniert?</p>
<pre><code class="language-cpp">class Test
{
public:
    void AddToMap(std::string Key, std::string Value)
    {
        // existier solch ein Eintrag bereits?
        std::map&lt;std::string, std::list&lt;std::string&gt; &gt;::iterator it = this-&gt;m_Map.find(Key);

        if (it != this-&gt;m_Map.end())
        {
            for (std::list&lt;std::string&gt;::iterator it2 = it-&gt;second.begin(); it2 != it-&gt;second.end(); ++it2)
            {
                if ((*it2) == Key)
                {
                    // ist bereits vorhanden
                    return;
                }
            }
        }

        // an dieser Stelle kann es nun sein, dass Key noch nicht in m_Map vorhanden ist
        // geht das hier trotzdem?
        this-&gt;m_Map[Key].push_back(Value);
        // wie man sieht, wird gleich die push_back-Funktion von std::list aufgerufen, obwohl ich selber keine Instanz erstellt habe
    }

private:
    std::map&lt;std::string, std::list&lt;std::string&gt; &gt; m_Map;
};
</code></pre>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987187</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Sun, 28 Nov 2010 19:39:06 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Sun, 28 Nov 2010 19:46:11 GMT]]></title><description><![CDATA[<p>Ja.</p>
<p><a href="http://www.cplusplus.com/reference/stl/map/operator%5B%5D/" rel="nofollow">http://www.cplusplus.com/reference/stl/map/operator[]/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987192</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987192</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 28 Nov 2010 19:46:11 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Sun, 28 Nov 2010 19:47:00 GMT]]></title><description><![CDATA[<p><a href="http://www.cplusplus.com/reference/stl/map/operator%5B%5D/" rel="nofollow">http://www.cplusplus.com/reference/stl/map/operator[]/</a></p>
<p>// edit:<br />
Jaja, zu spät <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987193</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987193</guid><dc:creator><![CDATA[l&#x27;abra d&#x27;or]]></dc:creator><pubDate>Sun, 28 Nov 2010 19:47:00 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Sun, 28 Nov 2010 19:49:15 GMT]]></title><description><![CDATA[<p>Wozu sind die ganzen this in deinem Code gut?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987195</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sun, 28 Nov 2010 19:49:15 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Sun, 28 Nov 2010 19:57:21 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>Wozu sind die ganzen this in deinem Code gut?</p>
</blockquote>
<p>lol <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/1987198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987198</guid><dc:creator><![CDATA[trollig]]></dc:creator><pubDate>Sun, 28 Nov 2010 19:57:21 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Sun, 28 Nov 2010 20:53:57 GMT]]></title><description><![CDATA[<p>Danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987220</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987220</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Sun, 28 Nov 2010 20:53:57 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Sun, 28 Nov 2010 22:58:11 GMT]]></title><description><![CDATA[<p>Die Frage ist vollkommen berechtigt, denn die <code>this</code> sind hier für gar nix gut. Was das lol soll muss mir erstmal einer erklären.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987260</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987260</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 28 Nov 2010 22:58:11 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Sun, 28 Nov 2010 23:51:42 GMT]]></title><description><![CDATA[<p>Ist halt mein Stil. Dass man sie nicht benötigt weiß ich aber auch.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987274</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Sun, 28 Nov 2010 23:51:42 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 11:05:21 GMT]]></title><description><![CDATA[<p>Geht übrigens auch deutlich kürzer und korrekter Parameterübergabe:</p>
<pre><code class="language-cpp">#include &lt;list&gt;
#include &lt;algorithm&gt;

void AddToMap( const std::string&amp; Key, const std::string&amp; Value)
{
   typedef std::list&lt;std::string&gt; list_type;

   list_type::iterator pos == std::find( m_Map[Key].begin(), m_Map[Key].end(), Value );
   if( pos == m_Map[Key].end() ) pos-&gt;insert( Value );
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1987405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987405</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Mon, 29 Nov 2010 11:05:21 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 12:39:24 GMT]]></title><description><![CDATA[<p>Ähm. Fail. Hört sich ja gut an <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="🙂"
    /> Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987453</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Mon, 29 Nov 2010 12:39:24 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 15:24:24 GMT]]></title><description><![CDATA[<p>Ich benutze this wo immer nur es geht.<br />
Meine Member haben auch keine m_<em>, _</em> oder sonstige Präfixe.</p>
<p>Das alles ist doch nur eine Stilfrage. Oder gibt es da noch andere Gründe?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987587</guid><dc:creator><![CDATA[*.*]]></dc:creator><pubDate>Mon, 29 Nov 2010 15:24:24 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 16:51:48 GMT]]></title><description><![CDATA[<blockquote>
<p>Das alles ist doch nur eine Stilfrage. Oder gibt es da noch andere Gründe?</p>
</blockquote>
<p>Nein, manche finden this-&gt;that einfach überflüssig, da man auch einfach nur that schreiben könnte.<br />
Ich mag Prefixe wie m_, m oder my auch nicht, aber mir ist da noch nichts besseres eingefallen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987642</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987642</guid><dc:creator><![CDATA[that-&amp;gt;this]]></dc:creator><pubDate>Mon, 29 Nov 2010 16:51:48 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 20:09:10 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p>Geht übrigens auch deutlich kürzer und korrekter Parameterübergabe:</p>
<pre><code class="language-cpp">#include &lt;list&gt;
#include &lt;algorithm&gt;

void AddToMap( const std::string&amp; Key, const std::string&amp; Value)
{
   typedef std::list&lt;std::string&gt; list_type;

   list_type::iterator pos == std::find( m_Map[Key].begin(), m_Map[Key].end(), Value );
   if( pos == m_Map[Key].end() ) pos-&gt;insert( Value );
}
</code></pre>
</blockquote>
<p>Ja. Geht sogar noch korrekter:</p>
<pre><code class="language-cpp">#include &lt;list&gt;
#include &lt;algorithm&gt;

void AddToMap( const std::string&amp; Key, const std::string&amp; Value)
{
   typedef std::list&lt;std::string&gt; list_type;

   list_type::iterator pos == std::find( m_Map[Key].begin(), m_Map[Key].end(), Value );
//   if( pos == m_Map[Key].end() ) pos-&gt;insert( Value ); // big badaboom
   if( pos == m_Map[Key].end() ) m_Map[Key].push_back( Value );
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1987734</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987734</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 29 Nov 2010 20:09:10 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 20:31:16 GMT]]></title><description><![CDATA[<p>that-&gt;this schrieb:</p>
<blockquote>
<p>Nein, manche finden this-&gt;that einfach überflüssig [...]</p>
</blockquote>
<p>Das könnte er persönlich nehmen :p</p>
<p>that-&gt;this schrieb:</p>
<blockquote>
<p>Ich mag Prefixe wie m_, m oder my auch nicht, aber mir ist da noch nichts besseres eingefallen...</p>
</blockquote>
<p>Gar nichts? Im Zweifelsfall dann halt <code>this-&gt;</code> . Würde ich selbst zwar nicht machen (ich verwende <code>my</code> ), aber wäre halt auch eine Möglichkeit.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987750</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987750</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 29 Nov 2010 20:31:16 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 21:06:52 GMT]]></title><description><![CDATA[<p>Ich persönlich finde <code>m_</code> gut, und zwar weil...<br />
* immer brav <code>this-&gt;</code> zu schreiben nervt mich persönlich<br />
* immer brav <code>this-&gt;</code> zu schreiben kann man mal vergessen<br />
* wenn nurmehr <code>x</code> dasteht (statt <code>this-&gt;x</code> oder <code>m_x</code> ), ist nicht mehr ersichtlich ob etwas ein Member ist oder nicht (was ich für eine wichtige Information halte)</p>
<ul>
<li><code>m_</code> ist sehr gut sichtbar/schnell erkennbar und kürzer als <code>this-&gt;</code></li>
</ul>
<p>Ich wollter hier aber auch keine <code>m_</code> Diskussion lostreten.</p>
<p>Und &quot;my&quot; finde ich (fast) genauso schrecklich wie das grässliche &quot;its&quot; <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="😉"
    /><br />
(Wer &quot;its&quot; erfunden hat möchte ich sowieso wissen, dann schau ich mal bei dem vorbei und erzähl ihm was)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987770</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987770</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 29 Nov 2010 21:06:52 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 21:10:43 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Und &quot;my&quot; finde ich (fast) genauso schrecklich wie das grässliche &quot;its&quot; <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>
</blockquote>
<p>Naja, Unterstriche gibts bei mir nur in Makros, da möchte ich hier keine Ausnahme machen. Ich könnte aber auch einfach &quot;m&quot; nehmen. Steht eigentlich &quot;m_&quot; definitiv für &quot;member&quot;? <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>
<p>Ach ja, es gibt auch noch &quot;our&quot;... Für statische Variablen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
<p>hustbaer schrieb:</p>
<blockquote>
<p>(Wer &quot;its&quot; erfunden hat möchte ich sowieso wissen, dann schau ich mal bei dem vorbei und erzähl ihm was)</p>
</blockquote>
<p>Da würde ich mitkommen. Und dann können wir gleich noch den Erfindern von &quot;DrawLinie&quot; &amp; Co. einen Besuch abstatten <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987774</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987774</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 29 Nov 2010 21:10:43 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 21:11:11 GMT]]></title><description><![CDATA[<blockquote>
<p>Das könnte er persönlich nehmen :p</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
<blockquote>
<p>Gar nichts? Im Zweifelsfall dann halt this-&gt;.</p>
</blockquote>
<p>Ich verwende für Getter und Setter, wenn ich welche brauche, am liebsten die Namen der Attribute:</p>
<pre><code class="language-cpp">class XYZ
{
public:
  int data();
  void data(int newData);
private:
  int mData;
};
</code></pre>
<p>So ungefähr. Wenn ich das &quot;m&quot; in &quot;mData&quot; wegließe und einfach nur &quot;data&quot; schriebe, würde der Compiler zu Recht meckern. Allerdings möchte ich auch nicht getData() und setData() schreiben, da mir das momentan zu wortreich erscheint.</p>
<p>Ich bin momentan sowieso noch auf der Suche nach &quot;meinem&quot; Stil und momentan gefällt mir diese Art von Gettern und Settern am besten - nur muss ich deswegen irgendwelche Pre- oder Suffixe verweden.</p>
<blockquote>
<p>Und &quot;my&quot; finde ich (fast) genauso schrecklich wie das grässliche &quot;its&quot; <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>
</blockquote>
<p>Wo ist der große Unterschied zwischen &quot;my&quot; und &quot;m_&quot;? Also die Anzahl der Buchstaben kann es nicht sein.<br />
Bei &quot;its&quot; muss ich dir allerdings zustimmen, das ist schrecklich. Noch schlimmer für Attribute finde ich den Prefix &quot;the&quot;, den sie uns beim C++ Kurs an der Uni &quot;gelehrt&quot; haben. Für Argumente von Funktionen wurde dann &quot;a&quot; oder &quot;an&quot; verwendet... <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/1987778</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987778</guid><dc:creator><![CDATA[that-&amp;gt;this]]></dc:creator><pubDate>Mon, 29 Nov 2010 21:11:11 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 21:14:21 GMT]]></title><description><![CDATA[<p>Was ist &quot;its&quot;?<br />
Ich persönlich nutze auch <code>m_*</code> und zwar aus den von hustbaer genannten Gründen und weil der Unterstrich den Bezeichner deutlicher vom Präfix trennt. my finde ich sogar etwas ungünstig, wenn du wirklich x, y, z als Member halten möchtest. Weil sie leicht im Präfix untergehen und damit Fehler provozieren. Du meinst doch sowas wie <code>m_y</code> =&gt; <code>myy</code> ? <code>this</code> wird bei mir wirklich nur verwendet, wenn ich eine Referenz auf das Objekt benötige.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987780</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987780</guid><dc:creator><![CDATA[Nick Unbekannt]]></dc:creator><pubDate>Mon, 29 Nov 2010 21:14:21 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Mon, 29 Nov 2010 22:32:25 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/797">@Nick</a> Unbekannt:</p>
<blockquote>
<p>Du meinst doch sowas wie m_y =&gt; myy ? this wird bei mir wirklich nur verwendet, wenn ich eine Referenz auf das Objekt benötige.</p>
</blockquote>
<p>Ne, die &quot;my-Schreiber&quot; tun dann schon gross weiterschreiben, also &quot;myY&quot; in dem Fall (auch nicht viel besser).</p>
<blockquote>
<p>Was ist &quot;its&quot;?</p>
</blockquote>
<p>Naja &quot;sein&quot; halt. Quasi &quot;the object's Foo&quot; -&gt; &quot;it's Foo&quot; -&gt; &quot;itsFoo&quot; *würg* (das Forum braucht dringend ein Kotz-Emoticon - wobei Emoticon auch so ein Hasswort ist *g*)</p>
<p>Keine Ahnung wer auf die Schnapsidee gekommen ist. Ich gehe davon aus dass es jmd. war der keine Praxiserfahrung hat, aber &quot;tolle&quot; Ideen, d.h. vermutlich ein Prof an einer Uni/FH und/oder ein ((Lehr-)Buch-)Author.</p>
<p>*duck-und-weg*</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/12954">@Nexus</a>:</p>
<p>Nexus schrieb:</p>
<blockquote>
<p>Und dann können wir gleich noch den Erfindern von &quot;DrawLinie&quot; &amp; Co. einen Besuch abstatten <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Hat etwas gebraucht bis es *ding* gemacht hat... das war kein Verschreiber, oder?<br />
(An &quot;DrawLine&quot; hab' ich nämlich nichts auszusetzen)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987820</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987820</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 29 Nov 2010 22:32:25 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Tue, 30 Nov 2010 00:47:41 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>DocShoe schrieb:</p>
<blockquote>
<p>Geht übrigens auch deutlich kürzer und korrekter Parameterübergabe:</p>
<pre><code class="language-cpp">#include &lt;list&gt;
#include &lt;algorithm&gt;

void AddToMap( const std::string&amp; Key, const std::string&amp; Value)
{
   typedef std::list&lt;std::string&gt; list_type;

   list_type::iterator pos == std::find( m_Map[Key].begin(), m_Map[Key].end(), Value );
   if( pos == m_Map[Key].end() ) pos-&gt;insert( Value );
}
</code></pre>
</blockquote>
<p>Ja. Geht sogar noch korrekter:</p>
<pre><code class="language-cpp">#include &lt;list&gt;
#include &lt;algorithm&gt;

void AddToMap( const std::string&amp; Key, const std::string&amp; Value)
{
   typedef std::list&lt;std::string&gt; list_type;

   list_type::iterator pos == std::find( m_Map[Key].begin(), m_Map[Key].end(), Value );
//   if( pos == m_Map[Key].end() ) pos-&gt;insert( Value ); // big badaboom
   if( pos == m_Map[Key].end() ) m_Map[Key].push_back( Value );
}
</code></pre>
</blockquote>
<p>Ihr seid ja wohl wahnsinnig geworden. m_Map[Key] jedes Mal neu rauskramen?</p>
<pre><code class="language-cpp">list_type &amp;ls = m_Map[Key];
if(std::find(ls.begin(), ls.end(), Value) == ls.end()) {
  ls.push_back(Value);
}
</code></pre>
<p>Natürlich könnte man auch eine std::map&lt;std::string, std::set<a href="std::string" rel="nofollow">std::string</a> &gt; benutzen und das Ganze auf</p>
<pre><code class="language-cpp">m_Map[Key].insert(Value);
</code></pre>
<p>zusammenstreichen. Wie sinnvoll das ist, hängt aber vom Anwendungsfall ab.</p>
<p>Was die Kennzeichnung von Member-Variablen angeht: ich benutze einen Unterstrich am Ende, bin aber der Ansicht, dass es wichtigere Dinge gibt, über die man sich streiten kann. this-&gt; als Präfix kann leicht mal vergessen werden und erfüllt dementsprechend nicht den Zweck der Übung, deswegen rate ich davon ab, und mit Unterstrichen als Präfix muss man sehr vorsichtig sein, keine für die Implementation reservierten Bezeichner zu benutzen, aber ob jetzt foo_, m_foo, mFoo, itsFoo oder myFoo ist doch letztendlich herzlich gleichgültig.</p>
<p>hustbaer schrieb:</p>
<blockquote>
<p>Naja &quot;sein&quot; halt. Quasi &quot;the object's Foo&quot; -&gt; &quot;it's Foo&quot; -&gt; &quot;itsFoo&quot; *würg* (das Forum braucht dringend ein Kotz-Emoticon - wobei Emoticon auch so ein Hasswort ist *g*)</p>
</blockquote>
<p>Ich fühle mich verpflichtet, darauf hinzuweisen, dass der Genitiv von &quot;it&quot; im Englischen &quot;its&quot; ist. &quot;it's&quot; ist eine Kontraktion von &quot;it is&quot;. Das ist ein Lieblingsfehler englischer Quasi-Analphabeten (sprich: Amerikaner <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="😉"
    /> ), der in Rechtschreibung bewanderte Engländer etwa so auf die Palme bringen kann, wie es bei uns mit &quot;wä_h_re&quot;, &quot;Standar_t_&quot; oder &quot;Vor_r_aus&quot; der Fall ist (dass ich die Fehler mit Unterstrichen markieren muss, um am Forenfilter vorbeizukommen, sollte den Punkt unterstreichen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987842</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987842</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Tue, 30 Nov 2010 00:47:41 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Tue, 30 Nov 2010 01:34:09 GMT]]></title><description><![CDATA[<p>@seldon:</p>
<p>seldon schrieb:</p>
<blockquote>
<p>Ihr seid ja wohl wahnsinnig geworden. m_Map[Key] jedes Mal neu rauskramen?</p>
</blockquote>
<p>Ich bin gar nicht wahnsinnig geworden, ich wollte lediglich auf einen Fehler hinweisen.<br />
Ich fühle mich nicht verpflichtet dabei gleich noch Code zu optimieren der mir eigentlich vollkommen schnuppe ist. (Mal ganz davon abgesehen dass es nicht immer sinnvoll ist alles zu optimieren, wenn man 'nem Anfänger was zeigen/erklären will)</p>
<p>seldon schrieb:</p>
<blockquote>
<p>hustbaer schrieb:</p>
<blockquote>
<p>Naja &quot;sein&quot; halt. Quasi &quot;the object's Foo&quot; -&gt; &quot;it's Foo&quot; -&gt; &quot;itsFoo&quot; *würg* (das Forum braucht dringend ein Kotz-Emoticon - wobei Emoticon auch so ein Hasswort ist *g*)</p>
</blockquote>
<p>Ich fühle mich verpflichtet, darauf hinzuweisen, dass der Genitiv von &quot;it&quot; im Englischen &quot;its&quot; ist. &quot;it's&quot; ist eine Kontraktion von &quot;it is&quot;. Das ist ein Lieblingsfehler englischer Quasi-Analphabeten (sprich: Amerikaner <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="😉"
    /> ), der in Rechtschreibung bewanderte Engländer etwa so auf die Palme bringen kann, wie es bei uns mit &quot;wä_h_re&quot;, &quot;Standar_t_&quot; oder &quot;Vor_r_aus&quot; der Fall ist (dass ich die Fehler mit Unterstrichen markieren muss, um am Forenfilter vorbeizukommen, sollte den Punkt unterstreichen).</p>
</blockquote>
<p>Zur Kenntnis genommen.</p>
<p>seldon schrieb:</p>
<blockquote>
<p>Was die Kennzeichnung von Member-Variablen angeht (...) bin aber der Ansicht, dass es wichtigere Dinge gibt, über die man sich streiten kann</p>
</blockquote>
<p>Wo wird hier gestritten? Ein Paar Leute haben ihre Präferenzen kundgetan, das ist auch schon alles.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987846</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987846</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 30 Nov 2010 01:34:09 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Tue, 30 Nov 2010 07:26:16 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Und &quot;my&quot; finde ich (fast) genauso schrecklich wie das grässliche &quot;its&quot; <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="😉"
    /><br />
(Wer &quot;its&quot; erfunden hat möchte ich sowieso wissen, dann schau ich mal bei dem vorbei und erzähl ihm was)</p>
</blockquote>
<p>Das &quot;its&quot; kenne ich aus dem &quot;Lehr&quot;buch &quot;C++ in 21 Tagen&quot; von Jesse Liberty, bei Markt+Technik erschienen, so ums Jahr 2000 rum. Damit habe ich damals _versucht_ mir C++ beizubringen. 5 Jahre später hab ichs dann nochmal mit einem gescheiten Buch probiert.</p>
<p>Der Liberty muss damals aber recht verbreitet gewesen sein, vielleicht hat er das etabliert.</p>
<p>Gruß,<br />
Phil</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1987868</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1987868</guid><dc:creator><![CDATA[PhilippM]]></dc:creator><pubDate>Tue, 30 Nov 2010 07:26:16 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Tue, 30 Nov 2010 16:40:23 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Hat etwas gebraucht bis es *ding* gemacht hat... das war kein Verschreiber, oder?<br />
(An &quot;DrawLine&quot; hab' ich nämlich nichts auszusetzen)</p>
</blockquote>
<p>Ja, ich hätte vielleicht ein eindeutigeres Beispiel wie &quot;ComputeAnzahlElements&quot; bringen können, aber ich hatte den Post schnell zu editieren, damit es überhaupt noch gelesen wird <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>
<p>Ein tatsächlich vorgekommenes, wirklich schlimmes Beispiel für so ein Gemisch weiss ich leider nicht gerade. Da sich theliquidwave nicht mehr für den Thread zu interessieren scheint – kennt jemand ein solches? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1988099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1988099</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 30 Nov 2010 16:40:23 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Tue, 30 Nov 2010 17:12:00 GMT]]></title><description><![CDATA[<p>Hey,<br />
nur weil mein &quot;Problem&quot; augenscheinlich gelöst ist, heißt das nicht, dass ich nicht mitlese <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Kurze Erklärung der Situation: In einem Spiel gibt es bestimmte Events, die per textbasierten Nachrichten ausgelöst werden. Beispielsweise: <code>round_start</code> oder <code>player_spawn</code> . Nun soll es möglich sein, pro Event beliebig viele &quot;Listener&quot; hinzuzufügen. Deshalb pro Key (also pro Eventname) eine std::list.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1988112</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1988112</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Tue, 30 Nov 2010 17:12:00 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Tue, 30 Nov 2010 18:40:59 GMT]]></title><description><![CDATA[<p>Sorry für die Unterstellung <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>
<p>Zu deiner Situation: Ich habe mal ein Event-System implementiert, allerdings mit <code>std::multimap</code> , in der die Keys die Eventnamen und die Values die Listener sind. Aber eine <code>std::list</code> in einer <code>std::map</code> geht auch gut. Hast du eigentlich eine konkrete Frage dazu?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1988159</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1988159</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 30 Nov 2010 18:40:59 GMT</pubDate></item><item><title><![CDATA[Reply to std::map - wird Instanz automatisch erstellt? on Tue, 30 Nov 2010 18:47:22 GMT]]></title><description><![CDATA[<p>Nein, habe ich nicht <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="😉"
    /><br />
Aber std::multimap kannte ich noch gar nicht. Sieht für meinen Fall eigentlich noch optimaler aus als meine Lösung, oder nicht?</p>
<p>Beziehungsweise, doch nicht. Wenn ich recht überlege, wird die Durchlaufzeit in einer for-Schleife länger sein, da ich bei meiner Lösung nur einmal nach dem Key suchen muss. Und es kommt hier eher auf die Zeit zum durchlaufen an, als die Zeit, die benötigt wird, um den Listener hinzuzufügen <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>
<p>Gruß und Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1988161</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1988161</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Tue, 30 Nov 2010 18:47:22 GMT</pubDate></item></channel></rss>