<?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[Functionen als Template Argument.]]></title><description><![CDATA[<p>Hallo,</p>
<p>wärend clang (clang version 3.5.0) folgenden Code problemlos ausführt, sagt g++ (g++ 4.8.1) nein das will ich nicht und beendet die Compiliererei mit der Fehlermeldung:</p>
<pre><code>error: ‘double(double)’ is not a valid type for a template non-type parameter
</code></pre>
<p><a href="http://ideone.com/6kTwCS" rel="nofollow">http://ideone.com/6kTwCS</a></p>
<pre><code>#include &lt;iostream&gt;

double add_one (double x)
{
	return x+1;
}

template &lt;typename Type, Type Instance&gt;
struct test_type
{
	double operator() (double x)
	{
		return Instance (x);
	}
};

int main ()
{
	test_type&lt;decltype(add_one), add_one&gt; test;

	std::cout &lt;&lt; test(10.0) &lt;&lt; &quot;\n&quot;;

	return 0;
}
</code></pre>
<p>Wäre nett wenn mich jemand aufklären könnte warum das so ist und was der Standard dazu sagt.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/325124/functionen-als-template-argument</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 11:11:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/325124.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Apr 2014 13:53:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Functionen als Template Argument. on Tue, 15 Apr 2014 13:53:09 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>wärend clang (clang version 3.5.0) folgenden Code problemlos ausführt, sagt g++ (g++ 4.8.1) nein das will ich nicht und beendet die Compiliererei mit der Fehlermeldung:</p>
<pre><code>error: ‘double(double)’ is not a valid type for a template non-type parameter
</code></pre>
<p><a href="http://ideone.com/6kTwCS" rel="nofollow">http://ideone.com/6kTwCS</a></p>
<pre><code>#include &lt;iostream&gt;

double add_one (double x)
{
	return x+1;
}

template &lt;typename Type, Type Instance&gt;
struct test_type
{
	double operator() (double x)
	{
		return Instance (x);
	}
};

int main ()
{
	test_type&lt;decltype(add_one), add_one&gt; test;

	std::cout &lt;&lt; test(10.0) &lt;&lt; &quot;\n&quot;;

	return 0;
}
</code></pre>
<p>Wäre nett wenn mich jemand aufklären könnte warum das so ist und was der Standard dazu sagt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394718</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394718</guid><dc:creator><![CDATA[ScottZhang]]></dc:creator><pubDate>Tue, 15 Apr 2014 13:53:09 GMT</pubDate></item><item><title><![CDATA[Reply to Functionen als Template Argument. on Tue, 15 Apr 2014 14:45:51 GMT]]></title><description><![CDATA[<p>Ja, das sollte problemlos kompilieren.</p>
<p>Folgendes erlaubt den Parameter</p>
<p>§14.1/8 schrieb:</p>
<blockquote>
<p>A non-type <em>template-parameter</em> of type “array of T” or “function returning T” is adjusted to be of type “pointer to T” or “pointer to function returning T”, respectively.</p>
</blockquote>
<p>und für dein Template-Argument trifft das zu</p>
<p>§14.3.2 schrieb:</p>
<blockquote>
<p>- a constant expression (5.19) that designates the address of a complete object with static storage duration and external or internal linkage or a function with external or internal linkage [...], expressed (ignoring parentheses) as <em>&amp; id-expression</em>, where the <em>id-expression</em> is the name of an object or function, except that the &amp; may be omitted if the name refers to a function or array[...]</p>
</blockquote>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394729</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 15 Apr 2014 14:45:51 GMT</pubDate></item><item><title><![CDATA[Reply to Functionen als Template Argument. on Tue, 15 Apr 2014 15:27:57 GMT]]></title><description><![CDATA[<p>Also verhält sich der g++ da nicht Standardkonform.</p>
<p>Das hab ich mir schon gedacht, denn das <a href="http://ideone.com/WEXcMI" rel="nofollow">http://ideone.com/WEXcMI</a> geht ja sowieso.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394742</guid><dc:creator><![CDATA[ScottZhang]]></dc:creator><pubDate>Tue, 15 Apr 2014 15:27:57 GMT</pubDate></item></channel></rss>