<?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[Probleme mit Librarys in Chatprogram]]></title><description><![CDATA[<p>Hallo zusammen!</p>
<p>ich habe in letzter Zeit ein einfaches Chatprogramm geschrieben, dass auf mehreren Projektes aufbaut:</p>
<p>-&gt;Shared<br />
-&gt;ServerBase<br />
-&gt;ServerGUI<br />
-&gt;ClientBase<br />
-&gt;ClientGUI</p>
<p>Erst hatte ich es so geplant, dass nur die &quot;Base&quot; projekte als lib compiled werden, Shared header allerdings includieren, jedoch nicht die shared.lib. Die GUI projekte sollten dann die base.lib includieren, um das ganze variabler zu halten.<br />
Wie auch immer, das hat nicht ganz funktioniert und jetzt &quot;erbt&quot; jedes projekt die lib des übergeordneten.<br />
Compilen tut alles fein, bis auf einen Fehler</p>
<pre><code>error LNK2001: Nicht aufgelöstes externes Symbol &quot;&quot;private: static class Chat::ACClient * Chat::Singleton&lt;class Chat::ACClient&gt;::m_instance&quot; (?m_instance@?$Singleton@VACClient@Chat@@@Chat@@0PAVACClient@2@A)&quot;.
</code></pre>
<p>Ich bin schon alle &quot;standard&quot; methoden die ich so kannte durchgegangen um den LNK fehler zu beheben, allerdings hat nichts geholfen.</p>
<p>hat einer eine idee woran das liegen könnte, oder tipps wie ich das projekt besser ordnen sollte?</p>
<p>Mfg, Xaser</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/286405/probleme-mit-librarys-in-chatprogram</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 21:36:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/286405.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 09 May 2011 12:43:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Mon, 09 May 2011 12:43:36 GMT]]></title><description><![CDATA[<p>Hallo zusammen!</p>
<p>ich habe in letzter Zeit ein einfaches Chatprogramm geschrieben, dass auf mehreren Projektes aufbaut:</p>
<p>-&gt;Shared<br />
-&gt;ServerBase<br />
-&gt;ServerGUI<br />
-&gt;ClientBase<br />
-&gt;ClientGUI</p>
<p>Erst hatte ich es so geplant, dass nur die &quot;Base&quot; projekte als lib compiled werden, Shared header allerdings includieren, jedoch nicht die shared.lib. Die GUI projekte sollten dann die base.lib includieren, um das ganze variabler zu halten.<br />
Wie auch immer, das hat nicht ganz funktioniert und jetzt &quot;erbt&quot; jedes projekt die lib des übergeordneten.<br />
Compilen tut alles fein, bis auf einen Fehler</p>
<pre><code>error LNK2001: Nicht aufgelöstes externes Symbol &quot;&quot;private: static class Chat::ACClient * Chat::Singleton&lt;class Chat::ACClient&gt;::m_instance&quot; (?m_instance@?$Singleton@VACClient@Chat@@@Chat@@0PAVACClient@2@A)&quot;.
</code></pre>
<p>Ich bin schon alle &quot;standard&quot; methoden die ich so kannte durchgegangen um den LNK fehler zu beheben, allerdings hat nichts geholfen.</p>
<p>hat einer eine idee woran das liegen könnte, oder tipps wie ich das projekt besser ordnen sollte?</p>
<p>Mfg, Xaser</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2060837</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2060837</guid><dc:creator><![CDATA[XaserIII]]></dc:creator><pubDate>Mon, 09 May 2011 12:43:36 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Mon, 09 May 2011 13:06:11 GMT]]></title><description><![CDATA[<p>hast du die m_instance variable denn auch definiert? Es reicht nicht aus, sie in der Klassendefinition zu deklarieren. Es sieht so aus, als wäre es ein statisches member eines Templates, also muss die Definition in den Header:</p>
<pre><code class="language-cpp">//test.h
template &lt;class T&gt;
class A
{
  static int i; //nur deklaration!
};

template &lt;class T&gt;
A&lt;T&gt;::int i; //definition!
</code></pre>
<p>Bei Bedarf kanst du die statische Variable auch initialisieren.</p>
<p>Ich würd allerdings die Singletoninstanz als statische Variable in der getInstance-Methode definieren, nicht als Klassenmember. Das verhindert Probleme mit der Initialisierungs-reihenfolge der statischen Variablen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2060845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2060845</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Mon, 09 May 2011 13:06:11 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Mon, 09 May 2011 13:13:40 GMT]]></title><description><![CDATA[<p>wow, das ist schonmal hilfreich, momentan sieht mein singleton so aus:</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
	class Singleton
	{
		static T* m_instance;

	public:

		Singleton()
		{
			if(m_instance != 0)
				throw std::exception(&quot;Instance already exists!&quot;);
			m_instance = (T*)this;
		}

		virtual ~Singleton()
		{
			if(m_instance != 0)
				delete m_instance;
			m_instance = 0;
		}

		static T* GetInstancePtr() { return m_instance; }
		static T&amp; GetInstance()
		{
			if(m_instance == 0)
				throw std::exception(&quot;Instance not yet created!&quot;);
			return *m_instance;
		}
	};
</code></pre>
<p>d.h. ich soll die m:istance einfach in GetInstance schieben? bzw und auch in GetInstancePtr?</p>
<p>Mfg, Xaser</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2060850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2060850</guid><dc:creator><![CDATA[XaserIII]]></dc:creator><pubDate>Mon, 09 May 2011 13:13:40 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Mon, 09 May 2011 13:29:59 GMT]]></title><description><![CDATA[<p>google mal nach &quot;meyers singleton&quot;.</p>
<p>Was mir an deinem singleton nicht gefällt:<br />
- der Konstruktor ist public - wozu?<br />
- du hantierst mit einem Pointer auf T. Mit dem meyers-Singleton geht das einfacher. Die ganzen Abfragen auf 0 entfallen dann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2060859</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2060859</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Mon, 09 May 2011 13:29:59 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Mon, 09 May 2011 16:51:46 GMT]]></title><description><![CDATA[<p>Ähm, habe jetzt nur kurz gegoogelt, da ich nur kurz am Rechner war, aber mir scheint als wäre der Meyer Singleton auch eingeschränkter, was die benutzung angeht. Momentan sieht meine Version des Meyer Singletons so aus:</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
class Singleton {
public:
static Singleton&amp; Instance() {
  static T m_instance;
  return m_instance;
}

private:
Singleton();
~Singleton();
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2060941</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2060941</guid><dc:creator><![CDATA[XaserIII]]></dc:creator><pubDate>Mon, 09 May 2011 16:51:46 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Mon, 09 May 2011 17:06:28 GMT]]></title><description><![CDATA[<p>XaserIII schrieb:</p>
<blockquote>
<p>Ähm, habe jetzt nur kurz gegoogelt, da ich nur kurz am Rechner war, aber mir scheint als wäre der Meyer Singleton auch eingeschränkter, was die benutzung angeht.</p>
</blockquote>
<p>Was meinst du mit &quot;eingeschränkt&quot;? Schließlich ist ja die Einschränkung Sinn &amp; Zweck eines Singletons <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/2060944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2060944</guid><dc:creator><![CDATA[freddixx]]></dc:creator><pubDate>Mon, 09 May 2011 17:06:28 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Mon, 09 May 2011 17:59:43 GMT]]></title><description><![CDATA[<p>damit meine ich, dass bsp weise man nicht einfach mehr einen pointer darauf bekommt oder sehe ich das jetzt komplett falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2060969</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2060969</guid><dc:creator><![CDATA[XaserIII]]></dc:creator><pubDate>Mon, 09 May 2011 17:59:43 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Mon, 09 May 2011 18:07:02 GMT]]></title><description><![CDATA[<p>XaserIII schrieb:</p>
<blockquote>
<p>damit meine ich, dass bsp weise man nicht einfach mehr einen pointer darauf bekommt oder sehe ich das jetzt komplett falsch?</p>
</blockquote>
<p><code>Singleton* ptr = &amp;Singleton&lt;..&gt;::Instance();</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2060972</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2060972</guid><dc:creator><![CDATA[fdfdg]]></dc:creator><pubDate>Mon, 09 May 2011 18:07:02 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Mon, 09 May 2011 19:10:57 GMT]]></title><description><![CDATA[<p>Hallo XaserIII ,</p>
<p>wofür brauchst du denn noch den Zeiger, wenn du eine Referenz erhältst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2061005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2061005</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Mon, 09 May 2011 19:10:57 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Tue, 10 May 2011 15:01:44 GMT]]></title><description><![CDATA[<p>Uh man, da hab ich jetzt aber wirklich gerade nicht nachgedacht, sorry. Aber wie kann man jetzt noch paramameter an den konstruktor der abegleiteten Klasse weitergeben?</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
	class Singleton
	{

	protected:

		Singleton() { }
		~Singleton() { }

	public:

		static T&amp; GetInstance()
		{
			static T m_instance;
			return m_instance;
		}
	};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2061286</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2061286</guid><dc:creator><![CDATA[XaserIII]]></dc:creator><pubDate>Tue, 10 May 2011 15:01:44 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Tue, 10 May 2011 20:03:37 GMT]]></title><description><![CDATA[<blockquote>
<pre><code class="language-cpp">if(m_instance != 0)
                delete m_instance;
</code></pre>
</blockquote>
<p>Das ist Blödsinn. Du kannst ein delete auf einen Nullzeiger ohne Probleme aufrufen, ja sogar folgendes ist erlaubt: <a href="http://ideone.com/rHSMo" rel="nofollow">http://ideone.com/rHSMo</a><br />
(Der C-Cast ist nur zu Demonstrationszwecken hier und natürlich hässlich.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2061424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2061424</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Tue, 10 May 2011 20:03:37 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Tue, 10 May 2011 20:10:41 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<blockquote>
<pre><code class="language-cpp">if(m_instance != 0)
                delete m_instance;
</code></pre>
</blockquote>
<p>Das ist Blödsinn. Du kannst ein delete auf einen Nullzeiger ohne Probleme aufrufen, ja sogar folgendes ist erlaubt: <a href="http://ideone.com/rHSMo" rel="nofollow">http://ideone.com/rHSMo</a><br />
(Der C-Cast ist nur zu Demonstrationszwecken hier und natürlich hässlich.)</p>
</blockquote>
<p>Der Code ist Blödsinn, die Begründung allerdings auch.<br />
Ein Test auf 0 ist zwar regelmäßig nicht erforderlich, deshalb aber nicht unbedingt sinnlos. Schließlich werden Programme nicht bloß ausgeführt sondern auch gelesen.</p>
<p>Hier hingegen ist der Test schlicht falsch:<br />
m_instance <em>kann/darf nicht</em> 0 sein, wäre es an dieser Stelle 0, läge ein Bug vor. Folglich gehört ein assert an diese Stelle.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2061425</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2061425</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 10 May 2011 20:10:41 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Tue, 10 May 2011 20:10:32 GMT]]></title><description><![CDATA[<p>XaserIII schrieb:</p>
<blockquote>
<p>Uh man, da hab ich jetzt aber wirklich gerade nicht nachgedacht, sorry. Aber wie kann man jetzt noch paramameter an den konstruktor der abegleiteten Klasse weitergeben?</p>
</blockquote>
<p>Ich würde eine Singleton-Klasse eher so entwerfen, daß sie ohne zusätzliche Parameter-Angaben erzeugt werden kann. Andernfalls bekommst du schnell Probleme mit der Initialisierungsreihenfolge.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2061426</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2061426</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 10 May 2011 20:10:32 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Tue, 10 May 2011 21:29:49 GMT]]></title><description><![CDATA[<p>Ja das war ja für mich gerade das schöne an meinem alten Singleton, dort konnte man quasi einfach new T(params) machen und die klasse war einmal initialisiert und konnte nicht nochmal erzeugt werden.</p>
<p>Hingegen mein neuer &quot;Meyers Singleton&quot; verhindert nichtmal das man nur eine instanz davon erzeugen kann, da der konstruktor von T public sein muss, damit das ganze funktioniert. Jedenfalls sehe ich das momentan so.</p>
<p>Wie sollte denn eine abstrakte Singleton Klasse aussehen, mit der man auch parameter an die abgeleiteten Klassen geben kann?</p>
<p>MfG, Xaser</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2061448</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2061448</guid><dc:creator><![CDATA[XaserIII]]></dc:creator><pubDate>Tue, 10 May 2011 21:29:49 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Tue, 10 May 2011 21:42:09 GMT]]></title><description><![CDATA[<p>Von wo aus bekommst du denn die Parameter übergeben? Wenn das aus dem Nutzer-Code kommt, hast du ein Problem weil du nicht weißt, welcher getInstance()-Aufruf tatsächlich der erste ist - der dann dein Singleton-Objekt initialisiert.</p>
<p>Und ich erinnere mich düster, daß Meyers auch wirksam verhindert hat daß du die Klasse manuell erzeugen kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2061461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2061461</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 10 May 2011 21:42:09 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Librarys in Chatprogram on Wed, 11 May 2011 06:38:30 GMT]]></title><description><![CDATA[<p>peww</p>
<p>Also das wäre natürlich fatal. da würde ich lieber bei meiner alten singleton klasse bleiben. Aber ich kann mir ehrlich gesagt nich vorstellen, dass man vom Meyers Singleton nicht eine version machen kann bei der man die abgeleitete Klasse mit Parametern initialisiert.</p>
<p>MfG, Xaser</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2061529</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2061529</guid><dc:creator><![CDATA[XaserIII]]></dc:creator><pubDate>Wed, 11 May 2011 06:38:30 GMT</pubDate></item></channel></rss>