<?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[Singleton per Makro?]]></title><description><![CDATA[<p>Wieso funktioniert das hier nicht wie gewünscht, der meint getInstance() sei private und ich kann nicht drauf zugreifen:</p>
<pre><code class="language-cpp">#define PUBLIC public:
#define PROTECTED protected:
#define PRIVATE private:
#define INTERN private:

#define FORBIDDEN_COPY(classname) private: classname (const classname&amp; rhs) {}
#define FORBIDDEN_ASSIGN(classname) private: classname&amp; operator= (const classname&amp; rhs) { return *this; }

#define MAKE_SINGLETON(classname) \
	PRIVATE classname (); \
	PUBLIC ~classname (); \
	PUBLIC static classname&amp; getInstance () { static classname object; return object; } \
	FORBIDDEN_COPY(classname) \
	FORBIDDEN_ASSIGN(classname)

class Example
{
    MAKE_SINGLETON(Example)
};
</code></pre>
<p>Bzw. gibts da sicher auch schönere Lösungen die ihr kennt? Wäre nett, ich will das nämlich vereinfachen und da nicht jedesmal x Methoden aufschreiben.</p>
<p>MfG SideWinder</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/118146/singleton-per-makro</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 08:16:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/118146.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Aug 2005 16:46:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Singleton per Makro? on Mon, 15 Aug 2005 16:46:34 GMT]]></title><description><![CDATA[<p>Wieso funktioniert das hier nicht wie gewünscht, der meint getInstance() sei private und ich kann nicht drauf zugreifen:</p>
<pre><code class="language-cpp">#define PUBLIC public:
#define PROTECTED protected:
#define PRIVATE private:
#define INTERN private:

#define FORBIDDEN_COPY(classname) private: classname (const classname&amp; rhs) {}
#define FORBIDDEN_ASSIGN(classname) private: classname&amp; operator= (const classname&amp; rhs) { return *this; }

#define MAKE_SINGLETON(classname) \
	PRIVATE classname (); \
	PUBLIC ~classname (); \
	PUBLIC static classname&amp; getInstance () { static classname object; return object; } \
	FORBIDDEN_COPY(classname) \
	FORBIDDEN_ASSIGN(classname)

class Example
{
    MAKE_SINGLETON(Example)
};
</code></pre>
<p>Bzw. gibts da sicher auch schönere Lösungen die ihr kennt? Wäre nett, ich will das nämlich vereinfachen und da nicht jedesmal x Methoden aufschreiben.</p>
<p>MfG SideWinder</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852707</guid><dc:creator><![CDATA[SideWinder]]></dc:creator><pubDate>Mon, 15 Aug 2005 16:46:34 GMT</pubDate></item><item><title><![CDATA[Reply to Singleton per Makro? on Mon, 15 Aug 2005 16:50:26 GMT]]></title><description><![CDATA[<p>Man kann den Singelton über ein Template realisieren.<br />
Man erhält dann zur Laufzeit das Verhalten eines Singeltons,<br />
ohne das man das Verhalten in der eigentlichen Klasse selber<br />
implementiert hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852709</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Mon, 15 Aug 2005 16:50:26 GMT</pubDate></item><item><title><![CDATA[Reply to Singleton per Makro? on Mon, 15 Aug 2005 16:52:25 GMT]]></title><description><![CDATA[<p>Hab nur beim Instanzieren einen Fehler gemacht, funktioniert also doch.</p>
<p>Aber kennt jemand schönere Lösungen?</p>
<p>MfG SideWinder</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852712</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852712</guid><dc:creator><![CDATA[SideWinder]]></dc:creator><pubDate>Mon, 15 Aug 2005 16:52:25 GMT</pubDate></item><item><title><![CDATA[Reply to Singleton per Makro? on Mon, 15 Aug 2005 16:53:04 GMT]]></title><description><![CDATA[<p>phlox81 schrieb:</p>
<blockquote>
<p>Man kann den Singelton über ein Template realisieren.<br />
Man erhält dann zur Laufzeit das Verhalten eines Singeltons,<br />
ohne das man das Verhalten in der eigentlichen Klasse selber<br />
implementiert hat.</p>
</blockquote>
<p>Kennst du da Links? Ich möchte eigentlich ganz einfach nur eine Zeile irgendwo hinklatschen und ein Singleton haben <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>MfG SideWinder</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852713</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852713</guid><dc:creator><![CDATA[SideWinder]]></dc:creator><pubDate>Mon, 15 Aug 2005 16:53:04 GMT</pubDate></item><item><title><![CDATA[Reply to Singleton per Makro? on Mon, 15 Aug 2005 16:59:47 GMT]]></title><description><![CDATA[<p>Kennst du Loki?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/852719</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852719</guid><dc:creator><![CDATA[holder]]></dc:creator><pubDate>Mon, 15 Aug 2005 16:59:47 GMT</pubDate></item><item><title><![CDATA[Reply to Singleton per Makro? on Mon, 15 Aug 2005 17:12:22 GMT]]></title><description><![CDATA[<p>Über die Forensuche wirst du leider wohl nix dazu finden <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>
<p>Dann paste ich den Code mal hier rein:</p>
<pre><code class="language-cpp">#ifndef Singelton_h
#define Singelton_h

template&lt;class T&gt;
class Singelton
{
	static T* singelton;
	static unsigned int n;
protected:
public:
	Singelton()
	{
		if(!singelton)
			singelton = new T;
		n++;
	};
	virtual ~Singelton(){
	if(!--n)
		delete singelton;
	};
	T* operator-&gt;()
	{
	return singelton;
	}
	T&amp; GetInstance()
	{
	return *singelton;
	}
};

template&lt;class T&gt; T* Singelton&lt;T&gt;::singelton;
template&lt;class T&gt; unsigned int Singelton&lt;T&gt;::n;
#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/852732</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/852732</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Mon, 15 Aug 2005 17:12:22 GMT</pubDate></item><item><title><![CDATA[Reply to Singleton per Makro? on Tue, 16 Aug 2005 12:03:54 GMT]]></title><description><![CDATA[<p>Die boost library enthält eine Klasse noncopyable, von der man ableiten kann. Schau dir das doch mal an.<br />
rya.<br />
Scorcher24</p>
]]></description><link>https://www.c-plusplus.net/forum/post/853309</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/853309</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Tue, 16 Aug 2005 12:03:54 GMT</pubDate></item><item><title><![CDATA[Reply to Singleton per Makro? on Tue, 16 Aug 2005 12:09:22 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<p>Die boost library enthält eine Klasse noncopyable, von der man ableiten kann. Schau dir das doch mal an.<br />
rya.<br />
Scorcher24</p>
</blockquote>
<p>hat doch gar nichst mit singletons zu tun. <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/853320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/853320</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Tue, 16 Aug 2005 12:09:22 GMT</pubDate></item><item><title><![CDATA[Reply to Singleton per Makro? on Tue, 16 Aug 2005 12:11:42 GMT]]></title><description><![CDATA[<p>#define FORBIDDEN_COPY(classname) private: classname (const classname&amp; rhs) {}<br />
#define FORBIDDEN_ASSIGN(classname) private: classname&amp; operator= (const classname&amp; rhs) { return *this; }</p>
<p>aber mit diesem code. und er wollte ne elegantere Lösung für den ganzen code wissen. Ich finde class foo : public noncopyable eleganter. Das ist alles.<br />
rya.<br />
Scorcher24</p>
]]></description><link>https://www.c-plusplus.net/forum/post/853325</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/853325</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Tue, 16 Aug 2005 12:11:42 GMT</pubDate></item><item><title><![CDATA[Reply to Singleton per Makro? on Tue, 16 Aug 2005 12:15:20 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<p>aber mit diesem code. und er wollte ne elegantere Lösung für den ganzen code wissen. Ich finde class foo : public noncopyable eleganter. Das ist alles.<br />
rya.<br />
Scorcher24</p>
</blockquote>
<p>jetzt wird mir es klar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/853331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/853331</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Tue, 16 Aug 2005 12:15:20 GMT</pubDate></item></channel></rss>