<?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[Probleme beim Typecast]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe folgende Klassen:<br />
<a href="//Cell.h">//Cell.h</a> Definitionen der Klassen Cell, BaseEl und C<br />
class Cell{<br />
private:<br />
Cell* next;<br />
public:<br />
Cell* getNext() const {return next;}<br />
...<br />
};</p>
<p>Class BaseEl : public Cell{<br />
private:<br />
int nummer;<br />
public:<br />
int getNummer() {return nummer;}<br />
...<br />
};</p>
<p>Class C : public BaseEl {<br />
private:<br />
string bem;<br />
public:<br />
void setBem(const string&amp; b) {bem = b;}<br />
const string&amp; getBem() const { return bem;}<br />
...<br />
};</p>
<p><a href="//InhomList.h">//InhomList.h</a> : Definition der Klasse InhomList<br />
#include &quot;Cell.h&quot;<br />
class InhomList {<br />
private:<br />
Cell* first;<br />
protected:<br />
Cell* getPos(int nr);<br />
...<br />
};</p>
<p><a href="//InhomList.cpp">//InhomList.cpp</a><br />
#include &quot;InhomList.h&quot;</p>
<p>Cell* InhomList::getPos(int nr) {<br />
Cell <em>pEl = first;<br />
while(pEl != NULL &amp;&amp;<br />
(nr != ((BaseEl</em>)pEl)-&gt; getNummer() )) //hier benötige ich einen Typecast<br />
pEl = pEl -&gt;getNext();<br />
...<br />
}</p>
<p>Ich habe schon einiges an Klammerungen für den Typecast nach BaseEl* ausprobiert aber nichts hat funktioniert. Hat irgendjemand eine Idee was ich falsch mache?</p>
<p>Viele Grüße<br />
Guido</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/148552/probleme-beim-typecast</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 21:48:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/148552.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 28 May 2006 08:13:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme beim Typecast on Sun, 28 May 2006 08:13:25 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe folgende Klassen:<br />
<a href="//Cell.h">//Cell.h</a> Definitionen der Klassen Cell, BaseEl und C<br />
class Cell{<br />
private:<br />
Cell* next;<br />
public:<br />
Cell* getNext() const {return next;}<br />
...<br />
};</p>
<p>Class BaseEl : public Cell{<br />
private:<br />
int nummer;<br />
public:<br />
int getNummer() {return nummer;}<br />
...<br />
};</p>
<p>Class C : public BaseEl {<br />
private:<br />
string bem;<br />
public:<br />
void setBem(const string&amp; b) {bem = b;}<br />
const string&amp; getBem() const { return bem;}<br />
...<br />
};</p>
<p><a href="//InhomList.h">//InhomList.h</a> : Definition der Klasse InhomList<br />
#include &quot;Cell.h&quot;<br />
class InhomList {<br />
private:<br />
Cell* first;<br />
protected:<br />
Cell* getPos(int nr);<br />
...<br />
};</p>
<p><a href="//InhomList.cpp">//InhomList.cpp</a><br />
#include &quot;InhomList.h&quot;</p>
<p>Cell* InhomList::getPos(int nr) {<br />
Cell <em>pEl = first;<br />
while(pEl != NULL &amp;&amp;<br />
(nr != ((BaseEl</em>)pEl)-&gt; getNummer() )) //hier benötige ich einen Typecast<br />
pEl = pEl -&gt;getNext();<br />
...<br />
}</p>
<p>Ich habe schon einiges an Klammerungen für den Typecast nach BaseEl* ausprobiert aber nichts hat funktioniert. Hat irgendjemand eine Idee was ich falsch mache?</p>
<p>Viele Grüße<br />
Guido</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066477</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066477</guid><dc:creator><![CDATA[GS74]]></dc:creator><pubDate>Sun, 28 May 2006 08:13:25 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme beim Typecast on Sun, 28 May 2006 10:10:45 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=2" rel="nofollow">Marc++us</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=8" rel="nofollow">Rund um die Programmierung</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066516</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066516</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sun, 28 May 2006 10:10:45 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme beim Typecast on Sun, 28 May 2006 10:28:51 GMT]]></title><description><![CDATA[<p>Versuch mal nen static_cast bzw dynamic_cast</p>
<pre><code class="language-cpp">static_cast&lt;BaseEl*&gt;(pEi);
//oder
dynamic_cast&lt;BaseEl*&gt;(pEi);
</code></pre>
<p>Welcher besser ist, weiss ich ned, ist Situationsabhängig.<br />
dynamic_cast macht glaub noch ne Überprüfung.</p>
<p>edit: <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-124249-and-highlight-is-%2Astatic%2A+%2Acast%2A.html" rel="nofollow">hier im Forum gut erklärt</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066523</guid><dc:creator><![CDATA[THX 1138]]></dc:creator><pubDate>Sun, 28 May 2006 10:28:51 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme beim Typecast on Sun, 28 May 2006 13:45:45 GMT]]></title><description><![CDATA[<p>Danke für den Tipp,</p>
<p>aber mit dem dynamic_cast funktioniert es auch nicht.<br />
Der Compiler meckert dann -&gt;getNummer() an.<br />
error C2446: '!=': Keine Konvertierung von 'Cell *' in 'int'</p>
<p>Viele Grüße<br />
Guido</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066664</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066664</guid><dc:creator><![CDATA[GS74]]></dc:creator><pubDate>Sun, 28 May 2006 13:45:45 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme beim Typecast on Sun, 28 May 2006 13:52:52 GMT]]></title><description><![CDATA[<p>Du sollst den Aufruf des Members auch nicht mit in den Cast packen.</p>
<pre><code class="language-cpp">dynamic_cast&lt;Cell*&gt;(pEl)-&gt;getNummer()
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1066672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066672</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Sun, 28 May 2006 13:52:52 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme beim Typecast on Sun, 28 May 2006 13:58:07 GMT]]></title><description><![CDATA[<p>Hallo LordJaxom,</p>
<p>habe ich auch nicht.<br />
Der Aufruf sieht bei mir folgendermaßen aus:</p>
<pre><code class="language-cpp">while(pEl != NULL &amp;&amp; (nr != dynamic_cast&lt;BaseEl*&gt;(pEl)-&gt;getNummer() ))
		pEl = pEl-&gt;getNummer();
</code></pre>
<p>Beim compilieren bekomme ich eine warning C4541: 'dynamic_cast' für polymorphen Typ 'Cell' mit /GR- verwendet; unvorhersehbares Verhalten möglich,<br />
sowie den error C2446</p>
<p>Gruß Guido</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066677</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066677</guid><dc:creator><![CDATA[GS74]]></dc:creator><pubDate>Sun, 28 May 2006 13:58:07 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme beim Typecast on Sun, 28 May 2006 14:09:47 GMT]]></title><description><![CDATA[<p>Okay, der erste Fehler deutet darauf hin dass Du die RTTI ausgeschaltet hast. Du solltest dem Rat des Compilers folgen und /GR- nicht benutzen.</p>
<p>Der zweite Fehler sollte eigentlich in der Zeile nach dem IF kommen, da Du einen int (getNummer()) einem Zeiger (pEl) zuweisen möchtest - dass der Fehler im IF kommt deutet für mich darauf hin dass getNummer() keinen int zurückgibt. Denn wenn man einen Zeiger nicht auf NULL vergleichen dürfte wäre wohl der Compiler (oder seine Standardbibliothek) kaputt, also muss sich der Fehler auf den zweiten Ungleich-Vergleich beziehen. Und hier wird nur ein int mit dem Rückgabetyp von getNummer() verglichen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066689</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066689</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Sun, 28 May 2006 14:09:47 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme beim Typecast on Sun, 28 May 2006 14:29:34 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>Dankeschön, Du hattest recht.<br />
getNummer() hat tatsächlich keinen int zurückgeliefert.</p>
<p>Gruß Guido</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066699</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066699</guid><dc:creator><![CDATA[GS74]]></dc:creator><pubDate>Sun, 28 May 2006 14:29:34 GMT</pubDate></item></channel></rss>