<?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[static variable nicht statisch?]]></title><description><![CDATA[<p>SDK_Base.h</p>
<pre><code class="language-cpp">#ifndef _SDK_BASE
#define _SDK_BASE

namespace SDK
{
#include &quot;CConfig.h&quot;
#include &quot;CServer.h&quot;
}
#endif
</code></pre>
<p>CServer.h</p>
<pre><code class="language-cpp">#ifndef _H_SERVER
#define _H_SERVER

class Server
{
public:
	void static __fastcall Init();
};

#endif
</code></pre>
<p>CServer.cpp</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &quot;SDK_Base.h&quot;

using namespace SDK;

void Server::Init() {
Console::Write(&quot;Listen_Port %p\n&quot;, &amp;Config::Server::Listen_Port);
}
</code></pre>
<p>CConfig.h</p>
<pre><code class="language-cpp">#ifndef _H_CCONFIG
#define _H_CCONFIG

namespace Config {
	void __fastcall Init();

	namespace Server {
		static int Listen_Port;
	}
}

#endif
</code></pre>
<p>CConfig.cpp</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &quot;SDK_Base.h&quot;

using namespace SDK;

void __fastcall Config::Init()
{
Console::Write(&quot;Listen_Port %p\n&quot;, &amp;Config::Server::Listen_Port);
}
</code></pre>
<p>So, dass Problem ist das bei CConfig die Variable Listen_Port eine andere Adresse hat als die bei CServer. Die Variable ist als static deklariert, müsste folglich immer die gleiche Adresse haben?<br />
Wenn ich das static weglassen will, kommt der Linker Fehler 2005 (LNK2005) dass die Variable schon in *.obj definiert worden ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/271954/static-variable-nicht-statisch</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 03:29:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/271954.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 06 Aug 2010 20:35:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to static variable nicht statisch? on Fri, 06 Aug 2010 20:37:23 GMT]]></title><description><![CDATA[<p>SDK_Base.h</p>
<pre><code class="language-cpp">#ifndef _SDK_BASE
#define _SDK_BASE

namespace SDK
{
#include &quot;CConfig.h&quot;
#include &quot;CServer.h&quot;
}
#endif
</code></pre>
<p>CServer.h</p>
<pre><code class="language-cpp">#ifndef _H_SERVER
#define _H_SERVER

class Server
{
public:
	void static __fastcall Init();
};

#endif
</code></pre>
<p>CServer.cpp</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &quot;SDK_Base.h&quot;

using namespace SDK;

void Server::Init() {
Console::Write(&quot;Listen_Port %p\n&quot;, &amp;Config::Server::Listen_Port);
}
</code></pre>
<p>CConfig.h</p>
<pre><code class="language-cpp">#ifndef _H_CCONFIG
#define _H_CCONFIG

namespace Config {
	void __fastcall Init();

	namespace Server {
		static int Listen_Port;
	}
}

#endif
</code></pre>
<p>CConfig.cpp</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &quot;SDK_Base.h&quot;

using namespace SDK;

void __fastcall Config::Init()
{
Console::Write(&quot;Listen_Port %p\n&quot;, &amp;Config::Server::Listen_Port);
}
</code></pre>
<p>So, dass Problem ist das bei CConfig die Variable Listen_Port eine andere Adresse hat als die bei CServer. Die Variable ist als static deklariert, müsste folglich immer die gleiche Adresse haben?<br />
Wenn ich das static weglassen will, kommt der Linker Fehler 2005 (LNK2005) dass die Variable schon in *.obj definiert worden ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1937282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1937282</guid><dc:creator><![CDATA[The.Pharao]]></dc:creator><pubDate>Fri, 06 Aug 2010 20:37:23 GMT</pubDate></item><item><title><![CDATA[Reply to static variable nicht statisch? on Fri, 06 Aug 2010 20:36:46 GMT]]></title><description><![CDATA[<p>Wie lautet die Frage?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1937283</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1937283</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 06 Aug 2010 20:36:46 GMT</pubDate></item><item><title><![CDATA[Reply to static variable nicht statisch? on Fri, 06 Aug 2010 20:40:29 GMT]]></title><description><![CDATA[<p>Indirekt^^<br />
Wie kann ich das Problem lösen, dass bei CConfig und CServer die gleiche Variable benutzt wird, sodass ich sie in CConfig ändern kann und sie in CServer übernommen wird. (Config::Server::Listen_Port)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1937287</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1937287</guid><dc:creator><![CDATA[The.Pharao]]></dc:creator><pubDate>Fri, 06 Aug 2010 20:40:29 GMT</pubDate></item><item><title><![CDATA[Reply to static variable nicht statisch? on Fri, 06 Aug 2010 20:45:06 GMT]]></title><description><![CDATA[<p>Wie ist es mit</p>
<p>CConfig.h</p>
<pre><code class="language-cpp">#ifndef _H_CCONFIG
#define _H_CCONFIG

namespace Config {
	void __fastcall Init();

	namespace Server {
		extern int Listen_Port;//nur anmelden, daß 
//sie in einer (anderen) Übersezungeeinheit liegt. 
	}
}

#endif
</code></pre>
<p>CConfig.cpp</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &quot;SDK_Base.h&quot;

using namespace SDK;

int Config::Server::Listen_Port;

void __fastcall Config::Init()
{
Console::Write(&quot;Listen_Port %p\n&quot;, &amp;Config::Server::Listen_Port);
}
</code></pre>
<p>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1937288</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1937288</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 06 Aug 2010 20:45:06 GMT</pubDate></item><item><title><![CDATA[Reply to static variable nicht statisch? on Fri, 06 Aug 2010 20:53:46 GMT]]></title><description><![CDATA[<p>Danke für die schnelle Antwort und die Erklärung für &quot;extern&quot;.<br />
Es funktioniert <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/1937292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1937292</guid><dc:creator><![CDATA[The.Pharao]]></dc:creator><pubDate>Fri, 06 Aug 2010 20:53:46 GMT</pubDate></item></channel></rss>