<?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[frage zur globalen STL map]]></title><description><![CDATA[<p>folgendes problem (hoffe jemand hat ne idee):</p>
<p>in file a.h:</p>
<pre><code>class A
{
  public:
   static map&lt;string, int&gt; s_map;
};
</code></pre>
<p>in file a.cpp</p>
<pre><code>map&lt;string, int&gt; A::s_map;
</code></pre>
<p>in file b.h</p>
<pre><code>#include &quot;a.h&quot;
class B
{
  private:
    B()
    {
      s_map.clear();
      s_map[&quot;hallo&quot;] = 1;
    }
  static B s_globalB;
};
</code></pre>
<p>in file b.cpp</p>
<pre><code>B B::s_globalB;
...
</code></pre>
<p>Unter windows crasht mein prog nach erfolgreicher compilierung<br />
in file a.h bei s_map.clear()</p>
<p>nur wieso ?!?!? das ding ist doch global (ueber default konstr.) angelegt.<br />
nur scheint nicht korrekt.</p>
<p>was mache ich falsch ???</p>
<p>vielen dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/252996/frage-zur-globalen-stl-map</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 03:19:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/252996.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 27 Oct 2009 13:07:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to frage zur globalen STL map on Tue, 27 Oct 2009 13:07:56 GMT]]></title><description><![CDATA[<p>folgendes problem (hoffe jemand hat ne idee):</p>
<p>in file a.h:</p>
<pre><code>class A
{
  public:
   static map&lt;string, int&gt; s_map;
};
</code></pre>
<p>in file a.cpp</p>
<pre><code>map&lt;string, int&gt; A::s_map;
</code></pre>
<p>in file b.h</p>
<pre><code>#include &quot;a.h&quot;
class B
{
  private:
    B()
    {
      s_map.clear();
      s_map[&quot;hallo&quot;] = 1;
    }
  static B s_globalB;
};
</code></pre>
<p>in file b.cpp</p>
<pre><code>B B::s_globalB;
...
</code></pre>
<p>Unter windows crasht mein prog nach erfolgreicher compilierung<br />
in file a.h bei s_map.clear()</p>
<p>nur wieso ?!?!? das ding ist doch global (ueber default konstr.) angelegt.<br />
nur scheint nicht korrekt.</p>
<p>was mache ich falsch ???</p>
<p>vielen dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1799092</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1799092</guid><dc:creator><![CDATA[pepe75]]></dc:creator><pubDate>Tue, 27 Oct 2009 13:07:56 GMT</pubDate></item><item><title><![CDATA[Reply to frage zur globalen STL map on Tue, 27 Oct 2009 13:12:10 GMT]]></title><description><![CDATA[<p>siehe <a href="http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12" rel="nofollow">hier</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1799096</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1799096</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Tue, 27 Oct 2009 13:12:10 GMT</pubDate></item><item><title><![CDATA[Reply to frage zur globalen STL map on Tue, 27 Oct 2009 14:19:39 GMT]]></title><description><![CDATA[<p>ihr seid die groessten <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="🙄"
    /><br />
ich verneige mich <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/1799135</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1799135</guid><dc:creator><![CDATA[pepe75]]></dc:creator><pubDate>Tue, 27 Oct 2009 14:19:39 GMT</pubDate></item><item><title><![CDATA[Reply to frage zur globalen STL map on Tue, 27 Oct 2009 15:13:32 GMT]]></title><description><![CDATA[<p>Benutz´ ein Singleton statt einer globalen Variable, damit löst sich dein Problem.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1799174</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1799174</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Tue, 27 Oct 2009 15:13:32 GMT</pubDate></item><item><title><![CDATA[Reply to frage zur globalen STL map on Tue, 27 Oct 2009 15:18:42 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p>Benutz´ ein Singleton statt einer globalen Variable, damit löst sich dein Problem.</p>
</blockquote>
<p>Vielleicht löst es sich bereits schon durch besseres Design. pepe75, brauchst du da wirklich eine statische/globale Variable? Es scheint mir auch merkwürdig, dass du die statische Variable in einer nicht-statischen Memberfunktion (Konstruktor <code>B::B()</code> ) veränderst. Oder experimentierst du nur etwas herum?</p>
<p>Ausserdem solltest du dir abgewöhnen, in Headerdateien <code>using namespace</code> zu schreiben, da dann der Namensraum in allen inkludierenden Dateien offengelegt wird, was das Konzept der Namensräume sinnlos macht und zu Namenskonflikten führen kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1799179</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1799179</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 27 Oct 2009 15:18:42 GMT</pubDate></item></channel></rss>