<?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[dynamic_cast und virtualle Ableitung]]></title><description><![CDATA[<p>Hallo Leute</p>
<p>ich kann den unten angegebenen Code komplieren,<br />
aber beim ausführen steigt es in der Zeile 49 (Long *longValue2 = dynamic_cast&lt;Long *&gt;(obj);) aus.<br />
Ich konnte nicht feststellen warum ?<br />
Ich bin für jede Hilfe dankbar.</p>
<pre><code>class Object{
	public:
		int i;
		Object();
		virtual ~Object();
};

class Number : public virtual Object{
	public:
		int n;
		Number();
		virtual ~Number();
};

class Long : public Number{
	public:
		int l;
		Long();
		virtual ~Long();
};

Object::Object()
{
	i = 0;
}

Object::~Object(){}

Number::Number():Object()
{
	n = 0;
}

Number::~Number(){}

Long::Long():Object(), Number()
{
	l = 0;
}

Long::~Long(){}

int main(int argc, char* argv[])
{
	Long l;
	Object *obj = &amp;l;
	Number *number = &amp;l;
	Long *longValue = (Long *) number;
	Long *longValue2 = dynamic_cast&lt;Long *&gt;(obj);

	printf(&quot;Hallo Welt!\n&quot;);
	return 0;
}
</code></pre>
<p>mfg<br />
funcky</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/225840/dynamic_cast-und-virtualle-ableitung</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 08:06:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/225840.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 25 Oct 2008 15:50:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to dynamic_cast und virtualle Ableitung on Sat, 25 Oct 2008 15:50:55 GMT]]></title><description><![CDATA[<p>Hallo Leute</p>
<p>ich kann den unten angegebenen Code komplieren,<br />
aber beim ausführen steigt es in der Zeile 49 (Long *longValue2 = dynamic_cast&lt;Long *&gt;(obj);) aus.<br />
Ich konnte nicht feststellen warum ?<br />
Ich bin für jede Hilfe dankbar.</p>
<pre><code>class Object{
	public:
		int i;
		Object();
		virtual ~Object();
};

class Number : public virtual Object{
	public:
		int n;
		Number();
		virtual ~Number();
};

class Long : public Number{
	public:
		int l;
		Long();
		virtual ~Long();
};

Object::Object()
{
	i = 0;
}

Object::~Object(){}

Number::Number():Object()
{
	n = 0;
}

Number::~Number(){}

Long::Long():Object(), Number()
{
	l = 0;
}

Long::~Long(){}

int main(int argc, char* argv[])
{
	Long l;
	Object *obj = &amp;l;
	Number *number = &amp;l;
	Long *longValue = (Long *) number;
	Long *longValue2 = dynamic_cast&lt;Long *&gt;(obj);

	printf(&quot;Hallo Welt!\n&quot;);
	return 0;
}
</code></pre>
<p>mfg<br />
funcky</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1604724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604724</guid><dc:creator><![CDATA[funcky]]></dc:creator><pubDate>Sat, 25 Oct 2008 15:50:55 GMT</pubDate></item><item><title><![CDATA[Reply to dynamic_cast und virtualle Ableitung on Sun, 26 Oct 2008 01:14:42 GMT]]></title><description><![CDATA[<p>Ich sehe da kein Problem. Wie meinst du steigt er aus?<br />
Wenn sich die Konsole einfach wieder schliesst und du das printf nicht siehst, dann ist das ganz normal. Da dein Programm zu Ende ist. Wenn du etwas sehen möchtest, dann musst du da noch warten..</p>
<p>Häng das mal unten an, anstatt printf: (noch #include &lt;iostream&gt; oben anfügen.)</p>
<pre><code class="language-cpp">std::cout &lt;&lt; &quot;Hallo, Welt&quot;;

std::cin.clear(); // Fehlerstates zurücksetzen
std::cin.ignore(std::cin.rdbuf()-&gt;in_avail());//alle Zeichen aus dem Buffer entfernen
std::cin.get(); //auf Eingabe warten
</code></pre>
<p>Achja:<br />
Downcasts sind in dem Sinne gefährlich, dass, wenn der Zieltyp keine Ableitung des Argumenttyps ist 0 zurückgegeben wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1604926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604926</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 26 Oct 2008 01:14:42 GMT</pubDate></item><item><title><![CDATA[Reply to dynamic_cast und virtualle Ableitung on Sun, 26 Oct 2008 07:56:00 GMT]]></title><description><![CDATA[<p>Ich meine auch das es kein Problem geben sollte. Allerdings steigt das Programm mit einer Exception aus. Mit welcher Exception kann ich nicht sehen.<br />
Mit dem unten angegebenen Code läuft das Programm durch.</p>
<pre><code>try{
Long *longValue2 = dynamic_cast&lt;Long *&gt;(obj);
} catch(...){}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1604950</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604950</guid><dc:creator><![CDATA[funcky]]></dc:creator><pubDate>Sun, 26 Oct 2008 07:56:00 GMT</pubDate></item><item><title><![CDATA[Reply to dynamic_cast und virtualle Ableitung on Sun, 26 Oct 2008 08:08:56 GMT]]></title><description><![CDATA[<p>Als Exception bekomme ich folgenden Meldung:Access violation - no RTTI data!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1604952</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604952</guid><dc:creator><![CDATA[funcky]]></dc:creator><pubDate>Sun, 26 Oct 2008 08:08:56 GMT</pubDate></item><item><title><![CDATA[Reply to dynamic_cast und virtualle Ableitung on Sun, 26 Oct 2008 08:13:06 GMT]]></title><description><![CDATA[<p>Hat sich erledigt. In den Projekteinstellungen war RTTI deaktiviert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1604953</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604953</guid><dc:creator><![CDATA[funcky]]></dc:creator><pubDate>Sun, 26 Oct 2008 08:13:06 GMT</pubDate></item><item><title><![CDATA[Reply to dynamic_cast und virtualle Ableitung on Sun, 26 Oct 2008 08:41:22 GMT]]></title><description><![CDATA[<p>funcky schrieb:</p>
<blockquote>
<p>Hat sich erledigt. In den Projekteinstellungen war RTTI deaktiviert.</p>
</blockquote>
<p>Das einstellen wäre noch von Vorteil, wenn man da dynamic_cast anwendet. <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="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1604958</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1604958</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 26 Oct 2008 08:41:22 GMT</pubDate></item></channel></rss>