<?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[double als konstanter Template-parameter]]></title><description><![CDATA[<pre><code class="language-cpp">template &lt;typename T, T top&gt; class X{}
</code></pre>
<p>funktioniert nicht, da:</p>
<pre><code class="language-cpp">X&lt;double, 1.0&gt; x;
</code></pre>
<p>double’ is not a valid type for a template constant parameter</p>
<p>C++ - standard:<br />
A non-type template-parameter shall not be declared to have floating<br />
point, class, or void type. [Example:<br />
template&lt;double d&gt; class X; // error<br />
template&lt;double* pd&gt; class Y; // OK<br />
template&lt;double&amp; rd&gt; class Z; // OK<br />
—end example]</p>
<p>Kann mann daraus etwas basteln so dass es trotzdem mit dopuble geht?</p>
<pre><code class="language-cpp">template &lt;typename T, T* top&gt; class X{}

double* d = new double(1.0);
X&lt;double, d&gt; x;
</code></pre>
<p>fuehrt zu<br />
is not a valid template argument for type ‘double*’ because it is not a constant pointer</p>
<p>Wie gehts richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/171096/double-als-konstanter-template-parameter</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 18:05:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/171096.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Jan 2007 14:56:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to double als konstanter Template-parameter on Mon, 22 Jan 2007 14:56:54 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template &lt;typename T, T top&gt; class X{}
</code></pre>
<p>funktioniert nicht, da:</p>
<pre><code class="language-cpp">X&lt;double, 1.0&gt; x;
</code></pre>
<p>double’ is not a valid type for a template constant parameter</p>
<p>C++ - standard:<br />
A non-type template-parameter shall not be declared to have floating<br />
point, class, or void type. [Example:<br />
template&lt;double d&gt; class X; // error<br />
template&lt;double* pd&gt; class Y; // OK<br />
template&lt;double&amp; rd&gt; class Z; // OK<br />
—end example]</p>
<p>Kann mann daraus etwas basteln so dass es trotzdem mit dopuble geht?</p>
<pre><code class="language-cpp">template &lt;typename T, T* top&gt; class X{}

double* d = new double(1.0);
X&lt;double, d&gt; x;
</code></pre>
<p>fuehrt zu<br />
is not a valid template argument for type ‘double*’ because it is not a constant pointer</p>
<p>Wie gehts richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1214527</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1214527</guid><dc:creator><![CDATA[Frager]]></dc:creator><pubDate>Mon, 22 Jan 2007 14:56:54 GMT</pubDate></item><item><title><![CDATA[Reply to double als konstanter Template-parameter on Mon, 22 Jan 2007 15:45:25 GMT]]></title><description><![CDATA[<p>Probier mal:</p>
<pre><code class="language-cpp">template &lt;typename T, const T* top&gt; class X{} 

static const double d = 1.0;

X&lt;double, &amp;d&gt; x;
</code></pre>
<p>edit: const eingefügt (wenn nur lesend auf d zugegriffen wird), ansonsten kannst du bei beiden das const wieder entfernen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1214560</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1214560</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Mon, 22 Jan 2007 15:45:25 GMT</pubDate></item><item><title><![CDATA[Reply to double als konstanter Template-parameter on Tue, 23 Jan 2007 07:16:07 GMT]]></title><description><![CDATA[<p>In Kurzfassung: Die Template-Paramter muß der Compiler bereits zur Compile-Zeit auflösen. Deshalb kannst du dort keine double-Werte (die werden erst zur Laufzeit von der FPU erzeugt) oder dynamisch angelegte Zeiger übergeben (new holt sich auch erst zur Laufzeit seinen Speicher).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1214921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1214921</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 23 Jan 2007 07:16:07 GMT</pubDate></item><item><title><![CDATA[Reply to double als konstanter Template-parameter on Tue, 23 Jan 2007 10:01:59 GMT]]></title><description><![CDATA[<p>Thx.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1215048</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1215048</guid><dc:creator><![CDATA[Frager]]></dc:creator><pubDate>Tue, 23 Jan 2007 10:01:59 GMT</pubDate></item></channel></rss>