<?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[fehler mit vererbung und arrays]]></title><description><![CDATA[<p>Hallo,<br />
warum ist da unten die Bedingung beim Assert false?</p>
<pre><code class="language-cpp">class A {
public:
	int av;
};

class B : public A {
public:
	int bv;
};

void f (A* x) 
{
	x[1].av = 0;
}

main ()
{
	B y [100];
	y [0].bv = 1;	

	f (y);

        // ... vielleicht verstehe ich auch das Kommentar nicht
	// One of the B in the array has just been stomped on.
	// This assertion will fail.
	assert (y [0].bv == 1);
}
</code></pre>
<p>Gefunden unter: <a href="http://cpptips.hyperformix.com/cpptips/ptr_array_problem.txt" rel="nofollow">http://cpptips.hyperformix.com/cpptips/ptr_array_problem.txt</a></p>
<p>gruß von mir.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/174813/fehler-mit-vererbung-und-arrays</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 22:44:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/174813.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 04 Mar 2007 01:03:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to fehler mit vererbung und arrays on Sun, 04 Mar 2007 01:03:06 GMT]]></title><description><![CDATA[<p>Hallo,<br />
warum ist da unten die Bedingung beim Assert false?</p>
<pre><code class="language-cpp">class A {
public:
	int av;
};

class B : public A {
public:
	int bv;
};

void f (A* x) 
{
	x[1].av = 0;
}

main ()
{
	B y [100];
	y [0].bv = 1;	

	f (y);

        // ... vielleicht verstehe ich auch das Kommentar nicht
	// One of the B in the array has just been stomped on.
	// This assertion will fail.
	assert (y [0].bv == 1);
}
</code></pre>
<p>Gefunden unter: <a href="http://cpptips.hyperformix.com/cpptips/ptr_array_problem.txt" rel="nofollow">http://cpptips.hyperformix.com/cpptips/ptr_array_problem.txt</a></p>
<p>gruß von mir.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1238746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1238746</guid><dc:creator><![CDATA[cppuser]]></dc:creator><pubDate>Sun, 04 Mar 2007 01:03:06 GMT</pubDate></item><item><title><![CDATA[Reply to fehler mit vererbung und arrays on Mon, 05 Mar 2007 07:17:21 GMT]]></title><description><![CDATA[<p>Polymorphe Klassen in Arrays zu packen ist im Allgemeinen keine gute Idee. Die Klasse B ist ein ganzes Stück größer als ihre Mutterklasse A, aber das ist der Zeiger-Arithmetik egal. Das heißt im Klartext, x[1] ist das A-Objekt, das sizeof(A) Bytes vom Array-Anfang entfernt liegt - das ist irgendwo in der Mitte von y[0].</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1239318</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1239318</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 05 Mar 2007 07:17:21 GMT</pubDate></item></channel></rss>