<?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 static in Klasse benutzen?]]></title><description><![CDATA[<p>Hallo Forum,</p>
<p>wie benutzt man static in einer Klasse? Ich brauche eine Liste in die alle Instanzen meiner Klasse etwas hineinschreiben können.</p>
<pre><code class="language-cpp">// Source von bb.h
#include &lt;list&gt;
class bb {
public:
	static void ClearList();
private:
	static std::list&lt;int&gt; m_lstNumbers;
};

// Source von bb.cpp
#include &quot;bb.h&quot;
void bb::ClearList() {
	m_lstNumbers.clear();
}
</code></pre>
<p>Wenn ich das static weglasse funktioniert es. Wenn ich es hinzunehme erhalte ich:</p>
<blockquote>
<p>bb.obj : error LNK2001: unresolved external symbol &quot;private: static class std::list&lt;int,class std::allocator&lt;int&gt; &gt; bb::m_lstNumbers&quot; (?m_lstNumbers@bb@@0V?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi mathvariant="normal">@</mi><mi>H</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">list@HV?</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.69444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.01968em;">l</span><span class="mord mathit">i</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.08125em;">H</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mclose">?</span></span></span></span>allocator@H@std@@@std@@A)<br />
Debug/aa.exe : fatal error LNK1120: 1 unresolved externals</p>
</blockquote>
<p>Vielen Dank</p>
<p>Borgan</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/192443/wie-static-in-klasse-benutzen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 10:01:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/192443.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 Sep 2007 13:14:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie static in Klasse benutzen? on Fri, 14 Sep 2007 13:14:54 GMT]]></title><description><![CDATA[<p>Hallo Forum,</p>
<p>wie benutzt man static in einer Klasse? Ich brauche eine Liste in die alle Instanzen meiner Klasse etwas hineinschreiben können.</p>
<pre><code class="language-cpp">// Source von bb.h
#include &lt;list&gt;
class bb {
public:
	static void ClearList();
private:
	static std::list&lt;int&gt; m_lstNumbers;
};

// Source von bb.cpp
#include &quot;bb.h&quot;
void bb::ClearList() {
	m_lstNumbers.clear();
}
</code></pre>
<p>Wenn ich das static weglasse funktioniert es. Wenn ich es hinzunehme erhalte ich:</p>
<blockquote>
<p>bb.obj : error LNK2001: unresolved external symbol &quot;private: static class std::list&lt;int,class std::allocator&lt;int&gt; &gt; bb::m_lstNumbers&quot; (?m_lstNumbers@bb@@0V?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>l</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi mathvariant="normal">@</mi><mi>H</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">list@HV?</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.69444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.01968em;">l</span><span class="mord mathit">i</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.08125em;">H</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mclose">?</span></span></span></span>allocator@H@std@@@std@@A)<br />
Debug/aa.exe : fatal error LNK1120: 1 unresolved externals</p>
</blockquote>
<p>Vielen Dank</p>
<p>Borgan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1365269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1365269</guid><dc:creator><![CDATA[Borgan]]></dc:creator><pubDate>Fri, 14 Sep 2007 13:14:54 GMT</pubDate></item><item><title><![CDATA[Reply to Wie static in Klasse benutzen? on Fri, 14 Sep 2007 13:23:07 GMT]]></title><description><![CDATA[<p>Uh. Ich hätte zuerst im Web suchen sollen. Es hat die init gefehlt:<br />
std::list&lt;int&gt; bb::m_lstNumbers;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1365277</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1365277</guid><dc:creator><![CDATA[Borgan]]></dc:creator><pubDate>Fri, 14 Sep 2007 13:23:07 GMT</pubDate></item><item><title><![CDATA[Reply to Wie static in Klasse benutzen? on Fri, 14 Sep 2007 15:23:54 GMT]]></title><description><![CDATA[<p>Die &quot;init&quot; heisst &quot;Definition&quot; (&quot;lege bb::m_lstNumbers mit Typ Typ std::list&lt;int&gt; hier an&quot;).<br />
Das andere in der Klasse ist die &quot;Deklaration&quot; (&quot;es gibt irgendwo ein Ding namens bb::m_lstNumbers mit Typ std::list&lt;int&gt;&quot;).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1365361</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1365361</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 14 Sep 2007 15:23:54 GMT</pubDate></item></channel></rss>