<?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[Template, static_cast]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich habe ein Problem mit einer Bibliothek, in der sich folgendes findet:</p>
<p>template&lt;typename OldType, typename NewType&gt;<br />
struct cast_impl<br />
{<br />
static inline NewType run(const OldType&amp; x)<br />
{<br />
return static_cast&lt;NewType&gt;(x);<br />
}<br />
};</p>
<p>Dummerweise existiert für OldType kein Cast nach NewType und ich glaube, ein Cast läßt sich auch nicht hinzufügen, richtig? Daher anders herum, kann man dieses Template spezialisieren? Ich habe direkt darunter eingefügt:</p>
<p>template&lt;&gt;<br />
struct cast_impl&lt;const CORE::Expr,int&gt;<br />
{<br />
static inline int run(const CORE::Expr&amp; x)<br />
{<br />
return static_cast&lt;int&gt;(CGAL::to_double(x));<br />
}<br />
};</p>
<p>...aber der Compiler nimmt trotzdem das Template statt der Spezialisierung und schreibt:</p>
<p>invalid static_cast from type ‘const CORE::Expr’ to type ‘int’</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/318257/template-static_cast</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Jul 2026 10:51:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/318257.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 05 Jul 2013 20:01:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template, static_cast on Fri, 05 Jul 2013 20:01:16 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich habe ein Problem mit einer Bibliothek, in der sich folgendes findet:</p>
<p>template&lt;typename OldType, typename NewType&gt;<br />
struct cast_impl<br />
{<br />
static inline NewType run(const OldType&amp; x)<br />
{<br />
return static_cast&lt;NewType&gt;(x);<br />
}<br />
};</p>
<p>Dummerweise existiert für OldType kein Cast nach NewType und ich glaube, ein Cast läßt sich auch nicht hinzufügen, richtig? Daher anders herum, kann man dieses Template spezialisieren? Ich habe direkt darunter eingefügt:</p>
<p>template&lt;&gt;<br />
struct cast_impl&lt;const CORE::Expr,int&gt;<br />
{<br />
static inline int run(const CORE::Expr&amp; x)<br />
{<br />
return static_cast&lt;int&gt;(CGAL::to_double(x));<br />
}<br />
};</p>
<p>...aber der Compiler nimmt trotzdem das Template statt der Spezialisierung und schreibt:</p>
<p>invalid static_cast from type ‘const CORE::Expr’ to type ‘int’</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2336911</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2336911</guid><dc:creator><![CDATA[tcast]]></dc:creator><pubDate>Fri, 05 Jul 2013 20:01:16 GMT</pubDate></item><item><title><![CDATA[Reply to Template, static_cast on Fri, 05 Jul 2013 21:45:38 GMT]]></title><description><![CDATA[<p>Wirr.<br />
Die Fehlermeldung ist unvollständig.</p>
<p>Und meine Glaskugel sagt, dass wahrscheinlich cast_impl<a href="CORE::Expr,int" rel="nofollow">CORE::Expr,int</a> benutzt wird. Was nat. auch in der Fehlermeldung steht...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2336941</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2336941</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 05 Jul 2013 21:45:38 GMT</pubDate></item><item><title><![CDATA[Reply to Template, static_cast on Sat, 06 Jul 2013 09:57:26 GMT]]></title><description><![CDATA[<blockquote>
<p>ich glaube, ein Cast läßt sich auch nicht hinzufügen, richtig?</p>
</blockquote>
<p>Es kommt darauf an, wo. Du kannst bspw. einen expliziten* Konvertierungsoperator in <code>CORE::Expr</code> hinzufügen, der es in einen Skalar Konvertiert:</p>
<pre><code>template&lt;typename Arithmetic&gt;
explicit operator Arithmetic() const
{
    return CGAL::to_double(*this);
}
</code></pre>
<p><sup>(Ungetestet)</sup></p>
<p>camper schrieb:</p>
<blockquote>
<p>Was nat. auch in der Fehlermeldung steht...</p>
</blockquote>
<p>Wieso? Das wird nicht impliziert.<br />
Qualifiziert man einen bereits <code>const</code> -qualifizierten Typ noch einmal mit <code>const</code> , wirkt einfach [<a href="http://dcl.type.cv" rel="nofollow">dcl.type.cv</a>]/1.</p>
<p>~* Das ist erst seit C++11 möglich.~</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2336988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2336988</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 06 Jul 2013 09:57:26 GMT</pubDate></item></channel></rss>