<?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[fehler mit enable_if]]></title><description><![CDATA[<p>hallo</p>
<p>ich habe in dieser zeile</p>
<pre><code>typedef EnableIf&lt; ::std::numeric_limits&lt;unsigned long int&gt;::max() &gt; Sum, unsigned long int&gt;::Type ProbabilityType;
</code></pre>
<p>folgende fehler:</p>
<pre><code>error C2976: &quot;EnableIf&quot;: Nicht genügend template-Argumente.
error C2365: &quot;Sum&quot;: Erneute Definition; vorherige Definition war &quot;Enumerator&quot;.
error C2062: 'unsigned long'-Typ unerwartet
</code></pre>
<p>wobei Sum so definiert ist:</p>
<pre><code>enum
			{
				Sum = // ... irgendwas was aus anderen Quellen errechnet wird, alles zu Compiletime bekannt
			};
</code></pre>
<p>und EnableIf so:</p>
<pre><code>template&lt;bool Condition, typename T&gt;
	struct EnableIf;
	template&lt;typename T&gt;
	struct EnableIf&lt;true, T&gt;
	{
		typedef T Type;
	};
</code></pre>
<p>ich kann fehler nicht nachempfinden. ist es vielleicht weil der binäre operator &gt; als template-klammer interpretiert wird? ist der fehler überhaupt ein fehler nach dem standard? und wenn es das ist, wie schreibt man das richtig? ich hab bereits versucht die bedingung in klammern zu packen oder einen expliziten cast nach bool zu machen, funktionierte beides nicht.</p>
<p>gruss</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/322454/fehler-mit-enable_if</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Jul 2026 21:37:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/322454.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 21 Dec 2013 11:02:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to fehler mit enable_if on Sat, 21 Dec 2013 11:02:14 GMT]]></title><description><![CDATA[<p>hallo</p>
<p>ich habe in dieser zeile</p>
<pre><code>typedef EnableIf&lt; ::std::numeric_limits&lt;unsigned long int&gt;::max() &gt; Sum, unsigned long int&gt;::Type ProbabilityType;
</code></pre>
<p>folgende fehler:</p>
<pre><code>error C2976: &quot;EnableIf&quot;: Nicht genügend template-Argumente.
error C2365: &quot;Sum&quot;: Erneute Definition; vorherige Definition war &quot;Enumerator&quot;.
error C2062: 'unsigned long'-Typ unerwartet
</code></pre>
<p>wobei Sum so definiert ist:</p>
<pre><code>enum
			{
				Sum = // ... irgendwas was aus anderen Quellen errechnet wird, alles zu Compiletime bekannt
			};
</code></pre>
<p>und EnableIf so:</p>
<pre><code>template&lt;bool Condition, typename T&gt;
	struct EnableIf;
	template&lt;typename T&gt;
	struct EnableIf&lt;true, T&gt;
	{
		typedef T Type;
	};
</code></pre>
<p>ich kann fehler nicht nachempfinden. ist es vielleicht weil der binäre operator &gt; als template-klammer interpretiert wird? ist der fehler überhaupt ein fehler nach dem standard? und wenn es das ist, wie schreibt man das richtig? ich hab bereits versucht die bedingung in klammern zu packen oder einen expliziten cast nach bool zu machen, funktionierte beides nicht.</p>
<p>gruss</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2373132</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2373132</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Sat, 21 Dec 2013 11:02:14 GMT</pubDate></item><item><title><![CDATA[Reply to fehler mit enable_if on Sat, 21 Dec 2013 11:43:30 GMT]]></title><description><![CDATA[<p>asfdlol schrieb:</p>
<blockquote>
<p>ist es vielleicht weil der binäre operator &gt; als template-klammer interpretiert wird?</p>
</blockquote>
<p>ja</p>
<p>asfdlol schrieb:</p>
<blockquote>
<p>ist der fehler überhaupt ein fehler nach dem standard?</p>
</blockquote>
<p>ja</p>
<p>asfdlol schrieb:</p>
<blockquote>
<p>ich hab bereits versucht die bedingung in klammern zu packen oder einen expliziten cast nach bool zu machen, funktionierte beides nicht.</p>
</blockquote>
<p>zeigen, nicht beschreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2373134</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2373134</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 21 Dec 2013 11:43:30 GMT</pubDate></item><item><title><![CDATA[Reply to fehler mit enable_if on Sat, 21 Dec 2013 12:00:28 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>asfdlol schrieb:</p>
<blockquote>
<p>ich hab bereits versucht die bedingung in klammern zu packen oder einen expliziten cast nach bool zu machen, funktionierte beides nicht.</p>
</blockquote>
<p>zeigen, nicht beschreiben.</p>
</blockquote>
<pre><code>typedef EnableIf&lt; (::std::numeric_limits&lt;unsigned long int&gt;::max() &gt; Sum), unsigned long int&gt;::Type ProbabilityType;
</code></pre>
<pre><code>typedef EnableIf&lt; static_cast&lt;bool&gt;(::std::numeric_limits&lt;unsigned long int&gt;::max() &gt; Sum), unsigned long int&gt;::Type ProbabilityType;
</code></pre>
<p>ich hab es nun gelöst indem ich die bedingung in einen anderen unbenannten enumator gespeichert habe (diesmal jedoch mit dem makro aus &lt;climits&gt; da numeric_limits&lt;T&gt;::max() nicht zu compilezeit evaluiert werden konnte (was wahrscheinlich mit c++11 gehen würde)):</p>
<pre><code>struct Foo
{
	enum
	{
		Sum = 1
	};
private:
	enum
	{
		MyCondition = ULONG_MAX &gt; Sum
	};
public:
	typedef EnableIf&lt;MyCondition, unsigned long int&gt;::Type ProbabilityType;
};
</code></pre>
<p><a href="http://ideone.com/hqwH2u" rel="nofollow">http://ideone.com/hqwH2u</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2373135</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2373135</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Sat, 21 Dec 2013 12:00:28 GMT</pubDate></item><item><title><![CDATA[Reply to fehler mit enable_if on Sat, 21 Dec 2013 12:07:10 GMT]]></title><description><![CDATA[<p>asfdlol schrieb:</p>
<blockquote>
<pre><code>typedef EnableIf&lt; (::std::numeric_limits&lt;unsigned long int&gt;::max() &gt; Sum), unsigned long int&gt;::Type ProbabilityType;
</code></pre>
</blockquote>
<p>das ist <a href="http://ideone.com/EeBa8L" rel="nofollow">korrekt</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2373136</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2373136</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 21 Dec 2013 12:07:10 GMT</pubDate></item><item><title><![CDATA[Reply to fehler mit enable_if on Sat, 21 Dec 2013 12:29:48 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>asfdlol schrieb:</p>
<blockquote>
<pre><code>typedef EnableIf&lt; (::std::numeric_limits&lt;unsigned long int&gt;::max() &gt; Sum), unsigned long int&gt;::Type ProbabilityType;
</code></pre>
</blockquote>
<p>das ist <a href="http://ideone.com/EeBa8L" rel="nofollow">korrekt</a>.</p>
</blockquote>
<p>da hab ich wohl die compilermeldungen nicht richtig gelesen und übereilt gedacht, dass diese variante aus dem selben grund scheitert wie die allererste. ist aber wegen dem numeric_limits&lt;T&gt;::max() und dem fehlenden c++11 support:<br />
<a href="http://ideone.com/r9TI8w" rel="nofollow">http://ideone.com/r9TI8w</a></p>
<pre><code>prog.cpp:17:66: error: ‘std::numeric_limits&lt;long unsigned int&gt;::max()’ cannot appear in a constant-expression
     typedef EnableIf&lt; (::std::numeric_limits&lt;unsigned long int&gt;::max() &gt; Sum), unsigned long int&gt;::Type ProbabilityType;
</code></pre>
<p>als hätten sie max nicht auch als member machen können so wie digit10 etc. <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>alles klar, danke für deine hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2373138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2373138</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Sat, 21 Dec 2013 12:29:48 GMT</pubDate></item></channel></rss>