<?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[Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++?]]></title><description><![CDATA[<p>Gibt es ein &quot;isoftype&lt;&gt;&quot; in C++?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/123030/gibt-es-ein-quot-isoftype-lt-gt-quot-in-c</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 09:47:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/123030.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 12 Oct 2005 11:42:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 11:42:41 GMT]]></title><description><![CDATA[<p>Gibt es ein &quot;isoftype&lt;&gt;&quot; in C++?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890506</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890506</guid><dc:creator><![CDATA[isoftype]]></dc:creator><pubDate>Wed, 12 Oct 2005 11:42:41 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 11:50:46 GMT]]></title><description><![CDATA[<p>Meinst du sowas wie typeid bzw. dynamic_cast?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890519</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Wed, 12 Oct 2005 11:50:46 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 11:56:53 GMT]]></title><description><![CDATA[<p>Nein, ich möchte prüfen, ob ein Objekt von einem bestimmten Typ ist. Das ist doch einer Hauptfunktionen von RTTI, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890528</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890528</guid><dc:creator><![CDATA[isoftype]]></dc:creator><pubDate>Wed, 12 Oct 2005 11:56:53 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 11:57:42 GMT]]></title><description><![CDATA[<p>&quot;eine der Hauptfunktionen&quot; wollte ich sagen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890530</guid><dc:creator><![CDATA[isoftype]]></dc:creator><pubDate>Wed, 12 Oct 2005 11:57:42 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 12:13:55 GMT]]></title><description><![CDATA[<p>typeid liefert eine Struktur mit den nötigen Vergleichsinformationen. Aber für deine Zwecke mag auch &quot;if(dynamic_cast&lt;X&gt;(val)!=NULL) cout&lt;&lt;&quot;Typ stimmt&quot;;&quot; ausreichen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890553</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890553</guid><dc:creator><![CDATA[CS]]></dc:creator><pubDate>Wed, 12 Oct 2005 12:13:55 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 12:29:37 GMT]]></title><description><![CDATA[<p>CS schrieb:</p>
<blockquote>
<p>typeid liefert eine Struktur mit den nötigen Vergleichsinformationen. Aber für deine Zwecke mag auch &quot;if(dynamic_cast&lt;X&gt;(val)!=NULL) cout&lt;&lt;&quot;Typ stimmt&quot;;&quot; ausreichen.</p>
</blockquote>
<p>Das macht den Code völlig unlesbar!</p>
<p>Wenn schon, dann so:</p>
<pre><code class="language-cpp">template &lt; typename targetType, class sourceType &gt; inline bool is_of_type( sourceType arg1 ) {
   return dynamic_cast &lt; targetType &gt; ( arg1 ) != 0;
}

if ( is_of_type &lt; A* &gt; ( b ) ) ...
</code></pre>
<p>Warum ist das in der &lt;algorithm&gt; Library nicht drin?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890570</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890570</guid><dc:creator><![CDATA[isoftype]]></dc:creator><pubDate>Wed, 12 Oct 2005 12:29:37 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 12:44:29 GMT]]></title><description><![CDATA[<p>isoftype schrieb:</p>
<blockquote>
<p>CS schrieb:</p>
<blockquote>
<p>typeid liefert eine Struktur mit den nötigen Vergleichsinformationen. Aber für deine Zwecke mag auch &quot;if(dynamic_cast&lt;X&gt;(val)!=NULL) cout&lt;&lt;&quot;Typ stimmt&quot;;&quot; ausreichen.</p>
</blockquote>
<p>Das macht den Code völlig unlesbar!</p>
<p>Wenn schon, dann so:</p>
<pre><code class="language-cpp">template &lt; typename targetType, class sourceType &gt; inline bool is_of_type( sourceType arg1 ) {
   return dynamic_cast &lt; targetType &gt; ( arg1 ) != 0;
}

if ( is_of_type &lt; A* &gt; ( b ) ) ...
</code></pre>
</blockquote>
<p>Klar kannst du das auch machen, wenn es dich glücklich macht. Oder du schreibst:</p>
<pre><code class="language-cpp">#define is_of_type(x,y) dynamic_cast&lt;y&gt;(x) != 0

if( is_of_type(b,A*) ) ...
</code></pre>
<p>(ist noch kürzer, aber nicht ganz so sauber</p>
<blockquote>
<p>Warum ist das in der &lt;algorithm&gt; Library nicht drin?</p>
</blockquote>
<p>Vermutlich weil niemand das für nötig gehalten hat <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="😉"
    /><br />
(afaik gibt es bei MFC einen ähnlichen Mechanismus, aber nagel mich nicht darauf fest)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890586</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890586</guid><dc:creator><![CDATA[CS]]></dc:creator><pubDate>Wed, 12 Oct 2005 12:44:29 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 12:47:53 GMT]]></title><description><![CDATA[<p>isoftype schrieb:</p>
<blockquote>
<p>Warum ist das in der &lt;algorithm&gt; Library nicht drin?</p>
</blockquote>
<p>Weil man es eigentlich nie braucht. Wozu braucht man das denn? Damit eine Basisklasse ihre abgeleiteten Typen benennen kann? Das ist genau der falsche Einsatz von Vererbung und Polymorphie. In den vergleichsweise wenigen Szenarien, wo ein dynamic_cast gerechtfertigt ist, sollte man diesen auch in seiner vollen Hässlichkeit hinschreiben (müssen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890591</guid><dc:creator><![CDATA[7H3 N4C3R]]></dc:creator><pubDate>Wed, 12 Oct 2005 12:47:53 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 12:54:22 GMT]]></title><description><![CDATA[<p>7H3 N4C3R schrieb:</p>
<blockquote>
<p>Wozu braucht man das denn?</p>
</blockquote>
<p>Z.B. ich habe einen Typunabhängigen Container über eine reine virtuelle Basisklasse erzeugt, und möchte den Container bearbeiten, z.B. es ist ein Baum, und ich möchte den Baum parsen und den Typ der Objekte prüfen können, ohne eine Methode in die reine virtuelle Basisklasse einzufügen, die dann überall implementiert sein muss.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890598</guid><dc:creator><![CDATA[isoftype]]></dc:creator><pubDate>Wed, 12 Oct 2005 12:54:22 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 13:24:57 GMT]]></title><description><![CDATA[<p>isoftype schrieb:</p>
<blockquote>
<p>Z.B. ich habe einen Typunabhängigen Container</p>
</blockquote>
<p>Macht man in 90% der Fälle mit Templates.</p>
<p>isoftype schrieb:</p>
<blockquote>
<p>über eine reine virtuelle Basisklasse erzeugt, und möchte den Container bearbeiten, z.B. es ist ein Baum, und ich möchte den Baum parsen und den Typ der Objekte prüfen können, ohne eine Methode in die reine virtuelle Basisklasse einzufügen, die dann überall implementiert sein muss.</p>
</blockquote>
<p>Ich sehe nicht wieso da nicht eine pure virtuelle Methode und ein Upcast reichen, ja sogar eleganter sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890626</guid><dc:creator><![CDATA[Ben04]]></dc:creator><pubDate>Wed, 12 Oct 2005 13:24:57 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 13:28:45 GMT]]></title><description><![CDATA[<p>Wenn Du ein Kompositum hast und mit einem Besucher drüber laufen willst, dann ist das gerade so eine Situation, wo der Einsatz gerechtfertigt sein kann.</p>
<p>Allerdings</p>
<p>if ( is_of_type &lt; A* &gt; ( b ) )</p>
<p>if ( dynamic_cast &lt; A*&gt; ( b ) )</p>
<p>Fällt Dir was auf? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Durch den impliziten cast eines Pointers nach bool, löst sich die Notwendigkeit für ein &quot;isoftype&quot; in Luft auf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890628</guid><dc:creator><![CDATA[7H3 N4C3R]]></dc:creator><pubDate>Wed, 12 Oct 2005 13:28:45 GMT</pubDate></item><item><title><![CDATA[Reply to Gibt es ein &amp;quot;isoftype&amp;lt;&amp;gt;&amp;quot; in C++? on Wed, 12 Oct 2005 14:15:34 GMT]]></title><description><![CDATA[<p>Das ist aber eine Zweckentfremdung von dynamic_cast&lt;&gt;.</p>
<p>Ein is_of_type&lt;&gt; ist da viel deutlicher.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890694</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890694</guid><dc:creator><![CDATA[isoftype]]></dc:creator><pubDate>Wed, 12 Oct 2005 14:15:34 GMT</pubDate></item></channel></rss>