<?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[Addresse einer Instanzierung eines Funktionstemplates?]]></title><description><![CDATA[<p>Möp!</p>
<p>Kann man die Addresse einer bestimmten Instanzierung eines Funktionstemplates holen? Mein Compiler streikt nämlich gerade und ich finde den Fehler gerade nicht...</p>
<pre><code class="language-cpp">#define VIRTUAL_INIT(base, name, r, ...) \
	virtual_##name##_pf(pack&lt;__VA_ARGS__&gt;()) = &amp;virtual_##name##_wrapper_function&lt;r, base*, __VA_ARGS__&gt;;
</code></pre>
<pre><code class="language-cpp">#define VIRTUAL_FUNCTION_FAMILY(base, derived, name) \
	template &lt;typename R, typename... P&gt; \
	static R virtual_##name##_wrapper_function(base* obj, P&amp;&amp;... args) \
	{ \
		return static_cast&lt;derived*&gt;(obj)-&gt;virtual_##name##_pf(pack&lt;P...&gt;())(std::forward&lt;P&gt;(args)...); \
	}
</code></pre>
<p>Diese beiden Makros werden dann innerhalb einer Klasse verwendet. Hier noch ein (leider nicht kompilierbares) Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;utility&gt;

template &lt;typename...&gt;
struct pack {};

template &lt;typename... Args&gt;
pack&lt;Args...&gt; make_pack(Args&amp;&amp;...) { return pack&lt;Args...&gt;(); }

#define VIRTUAL_PURE_FUNCTION(name, r, ...) \
	r (*&amp; virtual_##name##_pf (pack&lt;__VA_ARGS__&gt;) const) (base*, __VA_ARGS__) \
	{ \
		static r (* pf) (base*, __VA_ARGS__) = 0; \
		return pf; \
	}

#define VIRTUAL_FUNCTION_FAMILY(base, derived, name) \
	template &lt;typename R, typename... P&gt; \
	static R virtual_##name##_wrapper_function(base* obj, P&amp;&amp;... args) \
	{ \
		return static_cast&lt;derived*&gt;(obj)-&gt;name(std::forward&lt;P&gt;(args)...); \
	}

#define VIRTUAL_INIT(base, name, r, ...) \
	virtual_##name##_pf(pack&lt;__VA_ARGS__&gt;()) = &amp;virtual_##name##_wrapper_function&lt;r, base*, __VA_ARGS__&gt;;

#define VIRTUAL_CALL(obj, name, ...) \
	(obj)-&gt;virtual_##name##_pf(make_pack(__VA_ARGS__))((obj), __VA_ARGS__);

struct base
{
	VIRTUAL_PURE_FUNCTION(println, void, int)
	VIRTUAL_PURE_FUNCTION(println, void, double)
};

struct derived : base
{
	derived()
	{
		VIRTUAL_INIT(base, println, void, int)
		VIRTUAL_INIT(base, println, void, double)
	}

	VIRTUAL_FUNCTION_FAMILY(base, derived, println)

	void println(int n)
	{
		std::cout &lt;&lt; n &lt;&lt; '\n';
	}

	void println(double n)
	{
		std::cout &lt;&lt; n &lt;&lt; '\n';
	}
};

int main()
{
	base* b = new derived;
	VIRTUAL_CALL(b, println, 5);
	return 0;
}
</code></pre>
<blockquote>
<p>../main.cpp:40:1: error: no matches converting function 'virtual_println_wrapper_function' to type 'void (<em>)(struct base</em>, int) {aka void (<em>)(struct base</em>, int)}'<br />
../main.cpp:44:2: error: candidate is: template&lt;class R, class ... P&gt; static R derived::virtual_println_wrapper_function(base*, P&amp;&amp; ...)<br />
../main.cpp:41:1: error: no matches converting function 'virtual_println_wrapper_function' to type 'void (<em>)(struct base</em>, double) {aka void (<em>)(struct base</em>, double)}'<br />
../main.cpp:44:2: error: candidate is: template&lt;class R, class ... P&gt; static R derived::virtual_println_wrapper_function(base*, P&amp;&amp; ...)</p>
</blockquote>
<p>Grüße,<br />
PI</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/292792/addresse-einer-instanzierung-eines-funktionstemplates</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 17:19:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/292792.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 18 Sep 2011 03:41:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Addresse einer Instanzierung eines Funktionstemplates? on Sun, 18 Sep 2011 04:29:23 GMT]]></title><description><![CDATA[<p>Möp!</p>
<p>Kann man die Addresse einer bestimmten Instanzierung eines Funktionstemplates holen? Mein Compiler streikt nämlich gerade und ich finde den Fehler gerade nicht...</p>
<pre><code class="language-cpp">#define VIRTUAL_INIT(base, name, r, ...) \
	virtual_##name##_pf(pack&lt;__VA_ARGS__&gt;()) = &amp;virtual_##name##_wrapper_function&lt;r, base*, __VA_ARGS__&gt;;
</code></pre>
<pre><code class="language-cpp">#define VIRTUAL_FUNCTION_FAMILY(base, derived, name) \
	template &lt;typename R, typename... P&gt; \
	static R virtual_##name##_wrapper_function(base* obj, P&amp;&amp;... args) \
	{ \
		return static_cast&lt;derived*&gt;(obj)-&gt;virtual_##name##_pf(pack&lt;P...&gt;())(std::forward&lt;P&gt;(args)...); \
	}
</code></pre>
<p>Diese beiden Makros werden dann innerhalb einer Klasse verwendet. Hier noch ein (leider nicht kompilierbares) Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;utility&gt;

template &lt;typename...&gt;
struct pack {};

template &lt;typename... Args&gt;
pack&lt;Args...&gt; make_pack(Args&amp;&amp;...) { return pack&lt;Args...&gt;(); }

#define VIRTUAL_PURE_FUNCTION(name, r, ...) \
	r (*&amp; virtual_##name##_pf (pack&lt;__VA_ARGS__&gt;) const) (base*, __VA_ARGS__) \
	{ \
		static r (* pf) (base*, __VA_ARGS__) = 0; \
		return pf; \
	}

#define VIRTUAL_FUNCTION_FAMILY(base, derived, name) \
	template &lt;typename R, typename... P&gt; \
	static R virtual_##name##_wrapper_function(base* obj, P&amp;&amp;... args) \
	{ \
		return static_cast&lt;derived*&gt;(obj)-&gt;name(std::forward&lt;P&gt;(args)...); \
	}

#define VIRTUAL_INIT(base, name, r, ...) \
	virtual_##name##_pf(pack&lt;__VA_ARGS__&gt;()) = &amp;virtual_##name##_wrapper_function&lt;r, base*, __VA_ARGS__&gt;;

#define VIRTUAL_CALL(obj, name, ...) \
	(obj)-&gt;virtual_##name##_pf(make_pack(__VA_ARGS__))((obj), __VA_ARGS__);

struct base
{
	VIRTUAL_PURE_FUNCTION(println, void, int)
	VIRTUAL_PURE_FUNCTION(println, void, double)
};

struct derived : base
{
	derived()
	{
		VIRTUAL_INIT(base, println, void, int)
		VIRTUAL_INIT(base, println, void, double)
	}

	VIRTUAL_FUNCTION_FAMILY(base, derived, println)

	void println(int n)
	{
		std::cout &lt;&lt; n &lt;&lt; '\n';
	}

	void println(double n)
	{
		std::cout &lt;&lt; n &lt;&lt; '\n';
	}
};

int main()
{
	base* b = new derived;
	VIRTUAL_CALL(b, println, 5);
	return 0;
}
</code></pre>
<blockquote>
<p>../main.cpp:40:1: error: no matches converting function 'virtual_println_wrapper_function' to type 'void (<em>)(struct base</em>, int) {aka void (<em>)(struct base</em>, int)}'<br />
../main.cpp:44:2: error: candidate is: template&lt;class R, class ... P&gt; static R derived::virtual_println_wrapper_function(base*, P&amp;&amp; ...)<br />
../main.cpp:41:1: error: no matches converting function 'virtual_println_wrapper_function' to type 'void (<em>)(struct base</em>, double) {aka void (<em>)(struct base</em>, double)}'<br />
../main.cpp:44:2: error: candidate is: template&lt;class R, class ... P&gt; static R derived::virtual_println_wrapper_function(base*, P&amp;&amp; ...)</p>
</blockquote>
<p>Grüße,<br />
PI</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2120682</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2120682</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 18 Sep 2011 04:29:23 GMT</pubDate></item><item><title><![CDATA[Reply to Addresse einer Instanzierung eines Funktionstemplates? on Sun, 18 Sep 2011 04:20:45 GMT]]></title><description><![CDATA[<p>Zuviel Code und die Makros machen das unleserlich.</p>
<p>Deshalb nur Allgemein:<br />
Adresse einer Template Funktion bekommt man genauso wie bei einer &quot;normalen&quot; funktione:</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
void foo(T) {}

int main() {
   void (*i)(int) = foo&lt;int&gt;;
   i(1);

   void (*f)(float) = foo&lt;float&gt;;
   f(.1);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2120683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2120683</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sun, 18 Sep 2011 04:20:45 GMT</pubDate></item><item><title><![CDATA[Reply to Addresse einer Instanzierung eines Funktionstemplates? on Sun, 18 Sep 2011 04:26:12 GMT]]></title><description><![CDATA[<p>Das habe ich vermutet. Aber ich suche schon seit 3 Stunden den Fehler und finde ihn nicht. Da zeige ich lieber meinen originalen Code, anstatt dann Tippfehler reinzubauen beim umbauen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Vielleicht hat ja trotzdem jemand die Muse sich dieses Gefrickel anzusehen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2120684</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2120684</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 18 Sep 2011 04:26:12 GMT</pubDate></item><item><title><![CDATA[Reply to Addresse einer Instanzierung eines Funktionstemplates? on Sun, 18 Sep 2011 04:44:56 GMT]]></title><description><![CDATA[<p>OT: Rechtschreibung</p>
<p>314159265358979 schrieb:</p>
<blockquote>
<p>Vielleicht hat ja trotzdem jemand die Mu<strong>s</strong>e sich dieses Gefrickel anzusehen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Mit Mu<strong>ß</strong>e bezeichnet man die Zeit, welche eine Person nach eigenem Wunsch nutzen kann, um sich zu erquicken und zu erbauen, etwa seiner Mu<strong>s</strong>e oder den Mu<strong>s</strong>en frönend.<br />
(Das als Eröffnungssatz Wikipedia? Da hat mal jemand seinen Heinz Erhardt gesehen; sehr gut! Trotzdem finde ich es sehr löb- und verwunderlich für die deutsche Wikipedia. Es wird sicher bald verernsthaftet.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2120685</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2120685</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 18 Sep 2011 04:44:56 GMT</pubDate></item><item><title><![CDATA[Reply to Addresse einer Instanzierung eines Funktionstemplates? on Sun, 18 Sep 2011 04:37:35 GMT]]></title><description><![CDATA[<p>Eigentlich meinte ich das andere Gefrickel <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2120686</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2120686</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 18 Sep 2011 04:37:35 GMT</pubDate></item><item><title><![CDATA[Reply to Addresse einer Instanzierung eines Funktionstemplates? on Sun, 18 Sep 2011 04:43:11 GMT]]></title><description><![CDATA[<p>Okay, ich habs nun selbst gelöst, allerdings zum Preis des Perfect Forwardings...</p>
<pre><code class="language-cpp">#define VIRTUAL_FUNCTION_FAMILY(base, derived, name) \
	template &lt;typename R, typename... P&gt; \
	static R virtual_##name##_wrapper_function(base* obj, P... args) \
	{ \
		return static_cast&lt;derived*&gt;(obj)-&gt;name(std::forward&lt;P&gt;(args)...); \
	}

#define VIRTUAL_INIT(base, name, r, ...) \
	virtual_##name##_pf(pack&lt;__VA_ARGS__&gt;()) = &amp;virtual_##name##_wrapper_function&lt;r, __VA_ARGS__&gt;;
</code></pre>
<p>Jemand ne Idee, wie ich das hinkriege?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2120687</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2120687</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 18 Sep 2011 04:43:11 GMT</pubDate></item><item><title><![CDATA[Reply to Addresse einer Instanzierung eines Funktionstemplates? on Sun, 18 Sep 2011 06:34:46 GMT]]></title><description><![CDATA[<p>was willst du da eigentlich erreichen?</p>
<p>//edit ich habe gerade den anderen Thread gesehen. Oh mein Gott. Das kann ich nicht unterstützen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2120691</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2120691</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Sun, 18 Sep 2011 06:34:46 GMT</pubDate></item><item><title><![CDATA[Reply to Addresse einer Instanzierung eines Funktionstemplates? on Sun, 18 Sep 2011 14:44:16 GMT]]></title><description><![CDATA[<p>Wieso nicht? Ich mach das doch nur zum Spaß <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2120840</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2120840</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 18 Sep 2011 14:44:16 GMT</pubDate></item></channel></rss>