<?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[MickSin und die Mixins]]></title><description><![CDATA[<p>Hallo da!</p>
<p>Gegeben folgender Code:</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
class Mixin {
   void Call() {
      // Hier würde ich gerne T::SomeFunc aufrufen, falls das existiert,
      // oder ansonsten DefaultImpl    
   }

   void DefaultImpl()
   {
   }
};

class A {
   void SomeFunc();
};

class B : A, Mixin&lt;B&gt; {
   void SomeFunc();
};
</code></pre>
<p>Kann man das im Kommentar beschriebene irgendwie umsetzen?<br />
Danke schonmal für Eure Anregungen!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/319884/micksin-und-die-mixins</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Jul 2026 18:33:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/319884.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 07 Sep 2013 07:26:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MickSin und die Mixins on Sat, 07 Sep 2013 07:26:09 GMT]]></title><description><![CDATA[<p>Hallo da!</p>
<p>Gegeben folgender Code:</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
class Mixin {
   void Call() {
      // Hier würde ich gerne T::SomeFunc aufrufen, falls das existiert,
      // oder ansonsten DefaultImpl    
   }

   void DefaultImpl()
   {
   }
};

class A {
   void SomeFunc();
};

class B : A, Mixin&lt;B&gt; {
   void SomeFunc();
};
</code></pre>
<p>Kann man das im Kommentar beschriebene irgendwie umsetzen?<br />
Danke schonmal für Eure Anregungen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2350839</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2350839</guid><dc:creator><![CDATA[MickSin]]></dc:creator><pubDate>Sat, 07 Sep 2013 07:26:09 GMT</pubDate></item><item><title><![CDATA[Reply to MickSin und die Mixins on Sat, 07 Sep 2013 08:00:30 GMT]]></title><description><![CDATA[<p>Soll <code>SomeFunc static</code> sein?</p>
<pre><code>#include &lt;iostream&gt;

template&lt;typename T&gt;
class Mixin
{
private:

	template&lt;typename T2&gt;
	static void CallImpl( decltype(&amp;T2::SomeFunc) )
	{
		T::SomeFunc();
	}

	template&lt;typename T2&gt;
	void CallImpl( ... )
	{
		DefaultImpl();
	}

public:

	void Call()
	{
		CallImpl&lt;T&gt;( NULL );
	}

   void DefaultImpl()
   {
		std::cout &lt;&lt; &quot;Mixin::DefaultImpl\n&quot;;
   }
};

struct A
{
   static void SomeFunc()
   {
		std::cout &lt;&lt; &quot;A::SomeFunc()\n&quot;;
   }
};

struct B {};

int main()
{
	Mixin&lt;A&gt;{}.Call();
	Mixin&lt;B&gt;{}.Call();
}
</code></pre>
<p>Bei dieser Version gibt es einen schlichten Compiler-Fehler wenn <code>SomeFunc</code> eine nicht-statische Memberfunktion ist...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2350842</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2350842</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 07 Sep 2013 08:00:30 GMT</pubDate></item><item><title><![CDATA[Reply to MickSin und die Mixins on Sat, 07 Sep 2013 08:24:21 GMT]]></title><description><![CDATA[<p>Spezialisiert auf non-static, static, und keine Memberfunktion: <a href="http://ideone.com/BjorWN" rel="nofollow">http://ideone.com/BjorWN</a></p>
<p>Diesmal auch ein wenig C++11-hafter mit <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2634.html" rel="nofollow">diesem Trick</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2350845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2350845</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 07 Sep 2013 08:24:21 GMT</pubDate></item><item><title><![CDATA[Reply to MickSin und die Mixins on Sat, 07 Sep 2013 18:34:08 GMT]]></title><description><![CDATA[<p>Danke für Deine Mühen ersteinmal, ich war leider heute den ganzen Tag unterwegs und bin nun zu kirre im Kopf um noch klar darüber nachzudenken, drum schaue ich mir das morgen in alter Frische an!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2350965</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2350965</guid><dc:creator><![CDATA[MickSin]]></dc:creator><pubDate>Sat, 07 Sep 2013 18:34:08 GMT</pubDate></item></channel></rss>