<?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[Vererbung]]></title><description><![CDATA[<p>Hallo,<br />
ich habe folgendes Programm geschrieben:</p>
<pre><code class="language-csharp">dekl.h

#include &lt;string.h&gt;
#include &lt;iostream.h&gt;
#include &lt;stdio.h&gt;
#include &lt;list.h&gt;
#include &lt;conio.h&gt;

class KFZ
{
private:
 string hersteller;
 float leihgebuehr;
public:
 KFZ(string herst, float leihg);
 friend ostream&amp; operator&lt;&lt;(ostream&amp; out, KFZ* kfz);
 virtual string status()=0;
};

class PKW : public KFZ
{
private:
 int tueren;
public:
 PKW(string herst, float leihg, int tuer);
 int getTueren();
 string status();
};

class TRANSPORTER : public KFZ
{
private:
 float ladekapazitaet;
public:
 TRANSPORTER(string herst, float leihg, float ladekapa);
 float getLadekapazitaet();
 string status();
};

class AUTOVERLEIHER
{
private:
 list&lt;KFZ*&gt;Kfzliste;
public:
 void hinzu(string herst, float leihg, int tuer);
 void hinzu(string herst, float leihg, float ladekapa);
 void hinzu(KFZ* kfz);
 void ausgabe();
 KFZ* fktminleihgeb();
 KFZ* fktminladekapa();
};

impl.cpp

#include &lt;typeinfo.h&gt;
#include &lt;string.h&gt;
#include &lt;vcl.h&gt;
#include &quot;dekl.h&quot;

KFZ::KFZ(string herst, float leihg)
{
 this-&gt;hersteller = herst;
 this-&gt;leihgebuehr = leihg;
}

PKW::PKW(string hersteller, float leihgebuehr, int tuer): KFZ(hersteller, leihgebuehr)
{
 this-&gt;tueren = tuer;
}

int PKW::getTueren()
{
 return (this-&gt;tueren);
}

string PKW::status()
{
 string typeInfo = typeid(*this).name();
 return typeInfo + &quot; &quot; + IntToStr(this-&gt;tueren).c_str();
}

TRANSPORTER::TRANSPORTER(string hersteller, float leihgebuehr, float ladekapa):
 KFZ(hersteller, leihgebuehr)
{
 this-&gt;ladekapazitaet = ladekapa;
}

float TRANSPORTER::getLadekapazitaet()
{
 return (this-&gt;ladekapazitaet);
}

string TRANSPORTER::status()
{
 string typeInfo = typeid(*this).name();
 return typeInfo + &quot; &quot; + FloatToStr(this-&gt;ladekapazitaet).c_str();
}

void AUTOVERLEIHER::hinzu(string hersteller, float leihgebuehr, int tuer)
{
 this-&gt;Kfzliste.push_back(dynamic_cast&lt;PKW*&gt;(new PKW(hersteller, leihgebuehr, tuer)));
}

void AUTOVERLEIHER::hinzu(string hersteller, float leihgebuehr, float ladekapa)
{
 this-&gt;Kfzliste.push_back(dynamic_cast&lt;PKW*&gt;(new TRANSPORTER(hersteller, leihgebuehr, ladekapa)));
}

void AUTOVERLEIHER::hinzu(KFZ* kfz)
{
 Kfzliste.push_back(kfz);
}

void AUTOVERLEIHER::ausgabe()
{
 list&lt;KFZ*&gt;::iterator beginn = this-&gt;Kfzliste.begin();
 list&lt;KFZ*&gt;::iterator ende = this-&gt;Kfzliste.end();
  for(list&lt;KFZ*&gt;::iterator iter = beginn; iter !=ende; iter++)
   {
    cout&lt;&lt;*iter&lt;&lt;'\n'&lt;&lt;(*iter)-&gt;status()&lt;&lt;'\n';
   }
}
</code></pre>
<p>nun meine frage:<br />
wie kann ich realisieren, dass der PKW mit der minimalen Leihgebühr ausgegeben wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/136509/vererbung</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 14:00:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/136509.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 10 Feb 2006 20:40:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vererbung on Fri, 10 Feb 2006 20:40:51 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe folgendes Programm geschrieben:</p>
<pre><code class="language-csharp">dekl.h

#include &lt;string.h&gt;
#include &lt;iostream.h&gt;
#include &lt;stdio.h&gt;
#include &lt;list.h&gt;
#include &lt;conio.h&gt;

class KFZ
{
private:
 string hersteller;
 float leihgebuehr;
public:
 KFZ(string herst, float leihg);
 friend ostream&amp; operator&lt;&lt;(ostream&amp; out, KFZ* kfz);
 virtual string status()=0;
};

class PKW : public KFZ
{
private:
 int tueren;
public:
 PKW(string herst, float leihg, int tuer);
 int getTueren();
 string status();
};

class TRANSPORTER : public KFZ
{
private:
 float ladekapazitaet;
public:
 TRANSPORTER(string herst, float leihg, float ladekapa);
 float getLadekapazitaet();
 string status();
};

class AUTOVERLEIHER
{
private:
 list&lt;KFZ*&gt;Kfzliste;
public:
 void hinzu(string herst, float leihg, int tuer);
 void hinzu(string herst, float leihg, float ladekapa);
 void hinzu(KFZ* kfz);
 void ausgabe();
 KFZ* fktminleihgeb();
 KFZ* fktminladekapa();
};

impl.cpp

#include &lt;typeinfo.h&gt;
#include &lt;string.h&gt;
#include &lt;vcl.h&gt;
#include &quot;dekl.h&quot;

KFZ::KFZ(string herst, float leihg)
{
 this-&gt;hersteller = herst;
 this-&gt;leihgebuehr = leihg;
}

PKW::PKW(string hersteller, float leihgebuehr, int tuer): KFZ(hersteller, leihgebuehr)
{
 this-&gt;tueren = tuer;
}

int PKW::getTueren()
{
 return (this-&gt;tueren);
}

string PKW::status()
{
 string typeInfo = typeid(*this).name();
 return typeInfo + &quot; &quot; + IntToStr(this-&gt;tueren).c_str();
}

TRANSPORTER::TRANSPORTER(string hersteller, float leihgebuehr, float ladekapa):
 KFZ(hersteller, leihgebuehr)
{
 this-&gt;ladekapazitaet = ladekapa;
}

float TRANSPORTER::getLadekapazitaet()
{
 return (this-&gt;ladekapazitaet);
}

string TRANSPORTER::status()
{
 string typeInfo = typeid(*this).name();
 return typeInfo + &quot; &quot; + FloatToStr(this-&gt;ladekapazitaet).c_str();
}

void AUTOVERLEIHER::hinzu(string hersteller, float leihgebuehr, int tuer)
{
 this-&gt;Kfzliste.push_back(dynamic_cast&lt;PKW*&gt;(new PKW(hersteller, leihgebuehr, tuer)));
}

void AUTOVERLEIHER::hinzu(string hersteller, float leihgebuehr, float ladekapa)
{
 this-&gt;Kfzliste.push_back(dynamic_cast&lt;PKW*&gt;(new TRANSPORTER(hersteller, leihgebuehr, ladekapa)));
}

void AUTOVERLEIHER::hinzu(KFZ* kfz)
{
 Kfzliste.push_back(kfz);
}

void AUTOVERLEIHER::ausgabe()
{
 list&lt;KFZ*&gt;::iterator beginn = this-&gt;Kfzliste.begin();
 list&lt;KFZ*&gt;::iterator ende = this-&gt;Kfzliste.end();
  for(list&lt;KFZ*&gt;::iterator iter = beginn; iter !=ende; iter++)
   {
    cout&lt;&lt;*iter&lt;&lt;'\n'&lt;&lt;(*iter)-&gt;status()&lt;&lt;'\n';
   }
}
</code></pre>
<p>nun meine frage:<br />
wie kann ich realisieren, dass der PKW mit der minimalen Leihgebühr ausgegeben wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/991207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991207</guid><dc:creator><![CDATA[Mr. Blonde]]></dc:creator><pubDate>Fri, 10 Feb 2006 20:40:51 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Fri, 10 Feb 2006 23:27:41 GMT]]></title><description><![CDATA[<p>Schreibe eine Funktion, die zwei KFZ an Hand ihrer Leigebühr vergleicht</p>
<pre><code class="language-cpp">bool compLeihgebuehr( const KFZ* a, const KFZ* b )
{
    return a-&gt;leihgebuehr &lt; b-&gt;leihgebuehr;
}
</code></pre>
<p>Damit das compilert, musst Du diese entweder zum Friend von KFZ machen</p>
<pre><code class="language-cpp">class KFZ
{
    friend bool compLeihgebuehr( const KFZ* a, const KFZ* b );
    // ..
</code></pre>
<p>oder die Leihgebühr über eine Methode erreichbar machen.</p>
<p>Dann kannst Du Dir mit dem Algorithmus 'min_element' (#include &lt;algorithm&gt;) das KFZ mit der kleinsten Leihgebür suchen lassen und es ausgeben. Zum Beispiel in der Methode 'ausgabe':</p>
<pre><code class="language-cpp">void AUTOVERLEIHER::ausgabe()
{
    list&lt;KFZ*&gt;::iterator beginn = this-&gt;Kfzliste.begin();
    list&lt;KFZ*&gt;::iterator ende = this-&gt;Kfzliste.end();
    for(list&lt;KFZ*&gt;::iterator iter = beginn; iter !=ende; iter++)
    {
        cout&lt;&lt; *iter &lt;&lt;'\n'&lt;&lt;(*iter)-&gt;status()&lt;&lt;'\n';
    }

    list&lt;KFZ*&gt;::iterator iMin = min_element( Kfzliste.begin(), Kfzliste.end(), &amp;compLeihgebuehr );
    cout &lt;&lt; &quot;KFZ mit minimaler Leihgebühr: &quot; &lt;&lt; *iMin &lt;&lt; endl;
}
</code></pre>
<p>Bem.: die Header iostream.h usw. sind veraltet. Besser &lt;iostream&gt;, &lt;string&gt; usw. benutzen</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/991282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991282</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Fri, 10 Feb 2006 23:27:41 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sat, 11 Feb 2006 10:57:52 GMT]]></title><description><![CDATA[<p>danke für die hilfe <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>
<p>aber jetzt meckert das programm rum, wenn ich die minimale Leihgebühr ausgeben will.</p>
<p>Er sagt mir, dass irgendwas mit dem ostream nicht hinhaut:</p>
<p>Unresolved external 'operator &lt;&lt;(_STL::basic_ostream&lt;char, _STL::char_traits&lt;char&gt; &gt;&amp;, KFZ <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="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/991399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991399</guid><dc:creator><![CDATA[Mr. Blonde]]></dc:creator><pubDate>Sat, 11 Feb 2006 10:57:52 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sat, 11 Feb 2006 11:17:42 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">cout &lt;&lt; &quot;KFZ mit minimaler Leihgebühr: &quot; &lt;&lt; **iMin &lt;&lt; endl;
</code></pre>
<p>Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/991404</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991404</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Sat, 11 Feb 2006 11:17:42 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sat, 11 Feb 2006 11:45:23 GMT]]></title><description><![CDATA[<p>jetzt meint er:<br />
E2094 'operator&lt;&lt;' ist im Typ 'ostream' für Argumente des Typs 'KFZ' nicht implementiert</p>
<p>ich werde noch wahnsinnig ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/991428</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991428</guid><dc:creator><![CDATA[Mr. Blonde]]></dc:creator><pubDate>Sat, 11 Feb 2006 11:45:23 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sat, 11 Feb 2006 11:49:43 GMT]]></title><description><![CDATA[<p>Du hast zwar den operator&lt;&lt;(ostream&amp;,Kfz*) als friend deiner Klasse deklariert, aber du hast ihn nicht definiert (sprich: Der Compiler weiß, daß es ihn gibt, aber nicht was er machen soll). Das führt dann zu dem genannten Linker-Fehler.<br />
Und einen operator&lt;&lt;(ostream&amp;,Kfz&amp;) gibt es überhaupt nicht, wie dein Compiler richtig erkannt hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/991431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991431</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sat, 11 Feb 2006 11:49:43 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sat, 11 Feb 2006 11:56:48 GMT]]></title><description><![CDATA[<p>also in etwa so?</p>
<p>ostream&amp; operator&lt;&lt;(ostream&amp; out, KFZ* kfz)<br />
{<br />
string herst = (*kfz).hersteller;<br />
float leihg = (*kfz).leihgebuehr;<br />
out&lt;&lt;herst&lt;&lt;&quot;, &quot;&lt;&lt;leihg;<br />
return out;<br />
}</p>
<p>dann stürzt er aber mit der Fehlermeldung:</p>
<p>&quot;... Exeption der Klasse EAccess Violation aufgetreten ...&quot;</p>
<p>ab?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/991439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991439</guid><dc:creator><![CDATA[Mr. Blonde]]></dc:creator><pubDate>Sat, 11 Feb 2006 11:56:48 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sat, 11 Feb 2006 12:00:26 GMT]]></title><description><![CDATA[<p>In Deinem Programm oben</p>
<p>Mr. Blonde schrieb:</p>
<blockquote>
<p>ich habe folgendes Programm geschrieben:</p>
<pre><code class="language-cpp">// dekl.h

class KFZ
{
private:
 string hersteller;
 float leihgebuehr;
public:
 KFZ(string herst, float leihg);
 friend ostream&amp; operator&lt;&lt;(ostream&amp; out, KFZ* kfz); // &lt;- hier
 virtual string status()=0;
};
</code></pre>
</blockquote>
<p>Hast Du einen Ausgabe-Operator für KFZ* definiert, aber keine Implementierung hinzugefügt. D.h., wenn Du die Methode AUTOVERLEIHER::ausgabe() aufrufst - mit der Erweiterung der minimalen Leihgebühr oder nicht, spielt keine Rolle - so meckert der Linker zu Recht die fehlende Implementierung an.</p>
<p>Überlicherweise schreibt man</p>
<pre><code class="language-cpp">friend ostream&amp; operator&lt;&lt;(ostream&amp; out, const KFZ&amp; kfz );
</code></pre>
<p>also die Ausgabe der KFZ und nicht dessen Pointer. Eine Implementierung könnte dann so aussehen:</p>
<pre><code class="language-cpp">ostream&amp; operator&lt;&lt;(ostream&amp; out, const KFZ&amp; kfz )
    {
        kfz.print( out );
        return out;
    }
</code></pre>
<p>und 'print' wird zu einer virtuellen Methode von KFZ</p>
<pre><code class="language-cpp">class KFZ
{
protected:
    virtual void print( std::ostream&amp; out ) =0; // pur virtual; muss überladen werden  
    // ...
</code></pre>
<p>die von jeder abgeleiteten Klasse überschrieben werden muss. Z.B.:</p>
<pre><code class="language-cpp">class PKW : public KFZ
{
protected:
    virtual void print( std::ostream&amp; out )
    {
        out &lt;&lt; &quot;Pkw &quot; &lt;&lt; tueren &lt;&lt; &quot;'türig&quot;;
    }
</code></pre>
<p>Der Aufruf der Ausgabe von einem Iterator aus list&lt; KFZ* &gt; ist dann so, wie schon von ZuK geschrieben.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/991442</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991442</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Sat, 11 Feb 2006 12:00:26 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sat, 11 Feb 2006 12:02:40 GMT]]></title><description><![CDATA[<p>Sorry. Ich sollte genauer lesen bevor ich Unsinn poste.<br />
Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/991444</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991444</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Sat, 11 Feb 2006 12:02:40 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sat, 11 Feb 2006 12:04:51 GMT]]></title><description><![CDATA[<p>ZuK schrieb:</p>
<blockquote>
<p>Sorry. Ich sollte genauer lesen bevor ich Unsinn poste.</p>
</blockquote>
<p>Hallo Kurt,</p>
<p>behaupte einfach, Du hast mein Posting vorhergesehen ;). Dann passt es.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/991447</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991447</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Sat, 11 Feb 2006 12:04:51 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sat, 11 Feb 2006 19:25:33 GMT]]></title><description><![CDATA[<p>Hallo, ich hab das Programm nochmal komplett umgemoddet:</p>
<p>dekl.h</p>
<pre><code class="language-csharp">#include &lt;iostream&gt;
#include &lt;list&gt;
#include &lt;conio&gt;
#include &lt;string&gt;
#include &lt;vcl&gt;

class KFZ;

class AUTOVERLEIHER
{
 private:
  list&lt;KFZ*&gt;Kfzliste;

 public:
  ~AUTOVERLEIHER();
  void aufnehmen(KFZ* kzf);
  KFZ* getMinladekapa(float ladekapazitaet);
  float getMinausleihgeb();
  void  anzeigen();
  float getTueren();

};

class KFZ
{
private:
 string hersteller;
 float leihgebuehr;

public:
 KFZ(const string&amp; Kfzhersteller, float Kfzleihgeb);
 virtual ~KFZ(){};   //benötigt um basisklassen virtuell zu setzen
 void getProfil();
 float getleihgebuehr();

};

// Klasse PKW -&gt; erbt von KFZ Hersteller und Leihgebuehr

class PKW : public virtual KFZ
{
private:

 int tueren;

public:

 PKW(int Pkwtueren, const string&amp; hersteller, float leihgebuehr);
 virtual void getProfil();   //wird virtual gesetzt aufgrund der mehrfachvererbung
                             //ohne mehrfachvererbung, müsste nur in der Basisklasse
                             //getProfile auf virtual gesetzt werden
 int gettueren();

};

class LKW : public virtual KFZ
{
private:
 float ladekapazitaet;

public:
 LKW(float LKWladekapazitaet, const string&amp; hersteller, float leihgebuehr);
 virtual void getProfil();
 float getLadekapazitaet();
};

class KOMBI : public PKW, public LKW
{
public:
 KOMBI(const string&amp; hersteller, float leihgebuehr, int tueren, float ladekapazitaet):
  KFZ(hersteller, leihgebuehr),PKW(tueren, hersteller, leihgebuehr), LKW(ladekapazitaet, hersteller, leihgebuehr){}
};
</code></pre>
<p>header:</p>
<pre><code class="language-csharp">#include &quot;dekl.h&quot;
#include &lt;typeinfo&gt;
//#include &lt;monsterKI.brain&gt;

KFZ::KFZ(const string&amp; Kfzhersteller, float Kfzleihgeb)
{
this-&gt;hersteller = Kfzhersteller;
this-&gt;leihgebuehr = Kfzleihgeb;
}

void KFZ::getProfil()
{
string TypeName = typeid(*this).name();
cout&lt;&lt;TypeName&lt;&lt;endl;
cout&lt;&lt;&quot;Hersteller: &quot;&lt;&lt;this-&gt;hersteller&lt;&lt;&quot; Leihgebuehr: &quot;&lt;&lt;this-&gt;leihgebuehr;
}

float KFZ::getleihgebuehr()
{
return (this-&gt;leihgebuehr);
}

PKW::PKW(int Pkwtueren, const string&amp; hersteller, float leihgebuehr) :
 KFZ(hersteller, leihgebuehr)
{
this-&gt;tueren = Pkwtueren;
}

int PKW::gettueren()
{
return (this-&gt;tueren);
}

void PKW::getProfil()
{
 KFZ::getProfil();
 cout&lt;&lt;&quot; Tueren: &quot;&lt;&lt;this-&gt;tueren&lt;&lt;endl;
}
// nächstes dingsbums

LKW::LKW(float Lkwladekapazitaet, const string&amp; hersteller, float leihgebuehr) :
 KFZ(hersteller, leihgebuehr)

{
this-&gt;ladekapazitaet = Lkwladekapazitaet;
}

float LKW::getLadekapazitaet()
{
return (this-&gt;ladekapazitaet);
}

void LKW::getProfil()
{
 KFZ::getProfil();
 cout&lt;&lt;&quot; Ladekapazitaet: &quot;&lt;&lt;this-&gt;ladekapazitaet&lt;&lt;endl;
}

void AUTOVERLEIHER::aufnehmen(KFZ* kfz)
{
 Kfzliste.push_back(kfz);
}

float AUTOVERLEIHER::getTueren()
{
 float gte = 1000;
 list&lt;KFZ*&gt;::iterator beginn = Kfzliste.begin();
 list&lt;KFZ*&gt;::iterator ende = Kfzliste.end();

  for(list&lt;KFZ*&gt;::iterator iter=beginn; iter != ende; iter++)
  {
   PKW *pkw = dynamic_cast&lt;PKW*&gt;(*iter);
   if(pkw &amp;&amp; ((*pkw).gettueren() &lt; gte))
    {
     gte = (*pkw).gettueren();
    }
   }
  return gte;
}

void AUTOVERLEIHER::anzeigen()
{
 list&lt;KFZ*&gt;::iterator beginn = Kfzliste.begin();
 list&lt;KFZ*&gt;::iterator ende = Kfzliste.end();

  for(list&lt;KFZ*&gt;::iterator iter=beginn; iter != ende; iter++)
  {
   (**iter).getProfil();
  }
}

AUTOVERLEIHER::~AUTOVERLEIHER()
{
 list&lt;KFZ*&gt;::iterator beginn = Kfzliste.begin();
 list&lt;KFZ*&gt;::iterator ende = Kfzliste.end();

  for(list&lt;KFZ*&gt;::iterator iter=beginn; iter != ende; iter++)
  {
  delete *iter;
  }
 Kfzliste.clear();
}

//Minimale Leihgebühr

float AUTOVERLEIHER::getMinausleihgeb()
{
 float me = 1000;
 list&lt;KFZ*&gt;::iterator beginn = Kfzliste.begin();
 list&lt;KFZ*&gt;::iterator ende = Kfzliste.end();

  for(list&lt;KFZ*&gt;::iterator iter=beginn; iter != ende; iter++)
  {
   PKW *pkw = dynamic_cast&lt;PKW*&gt;(*iter);
   if(pkw &amp;&amp; ((*pkw).getleihgebuehr() &lt; me))
    {
     me = (*pkw).getleihgebuehr();
    }
   }
  return me;
}
</code></pre>
<p>main:</p>
<pre><code class="language-csharp">#pragma hdrstop
#include &quot;impl.cpp&quot;
#pragma argsused

int main(int argc, char* argv[])
{

AUTOVERLEIHER a1;

PKW * p1 = new PKW(6, &quot; BMW&quot;, 1500);
PKW * p2 = new PKW(4, &quot; Renault&quot;, 500);
PKW * p3 = new PKW(2, &quot; XXX&quot;, 3000);

LKW *l1 = new LKW(50,&quot; LKW&quot;,400);
LKW *l2 = new LKW(30,&quot; W&quot;,600);
LKW *l3 = new LKW(2,&quot;H&quot;,3000);

KOMBI * k1 = new KOMBI(&quot;AK&quot;, 27.50,3,500);

a1.aufnehmen(dynamic_cast&lt;KFZ*&gt;(p1));
a1.aufnehmen(dynamic_cast&lt;KFZ*&gt;(p2));
a1.aufnehmen(dynamic_cast&lt;KFZ*&gt;(p3));
a1.aufnehmen(dynamic_cast&lt;KFZ*&gt;(l1));
a1.aufnehmen(dynamic_cast&lt;KFZ*&gt;(k1));

a1.anzeigen();

cout&lt;&lt;a1.getTueren()&lt;&lt;endl;
cout&lt;&lt;a1.getMinausleihgeb();

getch();
return 0;
}
</code></pre>
<p>nun meine frage: wie kann ich realisieren, dass ein KFZ mit einer Ladekapazität von z.B. 2 angezeigt wird?!</p>
<p>thx im voraus <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/991773</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/991773</guid><dc:creator><![CDATA[Mr. Blonde]]></dc:creator><pubDate>Sat, 11 Feb 2006 19:25:33 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sun, 12 Feb 2006 09:39:35 GMT]]></title><description><![CDATA[<p>Mr. Blonde schrieb:</p>
<blockquote>
<p>nun meine frage: wie kann ich realisieren, dass ein KFZ mit einer Ladekapazität von z.B. 2 angezeigt wird?!</p>
</blockquote>
<p>Schlecht. Da die Klasse AUTOVERLEIHER nur eine liste von Pointern auf KFZ speichert kannst du auch nur auf Variablen und Methoden zugreifen die in KFZ vorhanden sind und KFZ weiss nichts von einer Ladekapazität.<br />
Du könntest eventuell KFZ eine pure virtuelle Methode getLadeKapazitaet() geben und bei PKW immer 0 zurückgeben.<br />
Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/992019</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/992019</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Sun, 12 Feb 2006 09:39:35 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Sun, 12 Feb 2006 20:20:46 GMT]]></title><description><![CDATA[<p>mhhh ... kay</p>
<p>hab nochmal ne frage:</p>
<p>header:</p>
<pre><code class="language-csharp">#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;stdio&gt;
#include &lt;list&gt;

//hochschulangehörige
class HA
 {
  public:
   HA(string Name, string Vorname);
   friend ostream&amp; operator&lt;&lt;(ostream&amp; out, HA * ha);
   virtual string status() = 0;

  private:
   string HAName;
   string HAVorname;
 };

//studenten
class S:public HA
 {
  public:
   S(string Name, string Vorname, int MatrikelNummer);
   int getMatrNr();
   string status();

  private:
   int matrNr;

 };

//mitarbeiter
class MA:public HA
 {
  public:
   float mg();
   string  status();
   MA(string Name, string Vorname, float Monatsgehalt);
  private:
   float monatsgehalt;
 };

//hilfsklasse für suche nach matrikelnummer
class Funktor
 {
  public:
   Funktor(MatrikelNummer);
   bool operator() (HA * ha);

  private:
   int matrNr;
 };

//personalverwaltung
class PV
 {
  public:
   void hinzu(string Name, string Vorname, int MatrikelNummer);
   void hinzu(string Name, string Vorname, float Monatsgehalt);
   void hinzu(HA * ha);
   void ausgabe();
   HA * maxMg();
   HA * sucheStudent(int MatrikelNummer);
   ~PV();
  private:
   list&lt;HA *&gt; PersonenListe;
 };
</code></pre>
<p>dekl:</p>
<pre><code class="language-csharp">#include &quot;dekl.h&quot;
#include &lt;string&gt;
#include &lt;typeinfo&gt;
#include &lt;vcl&gt;

//HOCHSCHULANGEHÖRIGER
HA::HA(string Name, string Vorname)
 {
  this-&gt;HAName = Name;
  this-&gt;HAVorname = Vorname;
 }

 //MITARBEITER
MA::MA(string Name, string Vorname, float Monatsgehalt) : HA(Name, Vorname)
 {
  this-&gt;monatsgehalt = Monatsgehalt;
 }

float MA::mg()
 {
  return this-&gt;monatsgehalt;
 }
string MA::status()
 {
  string typeInfo = typeid (*this).name();
  return typeInfo + &quot; &quot; + FloatToStr(this-&gt;monatsgehalt).c_str();
 }

 //STUDENT
S::S(string Name, string Vorname, int MatrikelNummer):HA(Name, Vorname)
 {
  this-&gt;matrNr = MatrikelNummer;
 }

int S::getMatrNr()
 {
  return this-&gt;matrNr;
 }

string S::status()
 {
  string typeInfo = typeid(*this).name();
  return typeInfo + &quot; &quot; + IntToStr(this-&gt;matrNr).c_str();
 }

//PERSONALVERWALTUNG
//hinzufühen student
void PV::hinzu(string Name, string Vorname, int MatrikelNummer)
 {
  this-&gt;PersonenListe.push_back(dynamic_cast&lt;HA*&gt;(new S(Name, Vorname, MatrikelNummer)));
 }

//hinzufügen mitarbeiter
void PV::hinzu(string Name, string Vorname, float Monatsgehalt)
 {
  this-&gt;PersonenListe.push_back(dynamic_cast&lt;HA*&gt;(new MA(Name, Vorname, Monatsgehalt)));
 }

//ha hinzufügen
void PV::hinzu(HA * ha)
 {
  PersonenListe.push_back(ha);
 }

//ausgabe der kompletten hochschulangehörigenliste
void PV::ausgabe()
 {
  list&lt;HA*&gt;::iterator beginn = this-&gt;PersonenListe.begin();
  list&lt;HA*&gt;::iterator ende   = this-&gt;PersonenListe.end();

  for (list&lt;HA*&gt;::iterator iter = beginn;iter!=ende;iter++)
        {
         cout&lt;&lt;*iter&lt;&lt;'\n'&lt;&lt;(*iter)-&gt;status()&lt;&lt;'\n';
        }

 }

//suche maximales monatsgehalt
HA * PV::maxMg()
 {
  HA * returnha=NULL;
  float MaxMG = -1;
  list&lt;HA*&gt;::iterator beginn = this-&gt;PersonenListe.begin();
  list&lt;HA*&gt;::iterator ende   = this-&gt;PersonenListe.end();
  for (list&lt;HA*&gt;::iterator iter = beginn;iter!=ende;iter++)
        {
         MA * ma = dynamic_cast&lt;MA*&gt;(*iter);
         if (ma &amp;&amp; ((*ma).mg() &gt; MaxMG))
          {
           MaxMG = (*ma).mg();
           returnha = *iter;
          }
        }
  return returnha;
 }

//suche student über matrikelnummer
HA * PV::sucheStudent(int MatrikelNummer)
 {
  Funktor Fkt(MatrikelNummer);
  list&lt;HA*&gt;::iterator iter = find_if(PersonenListe.begin(), PersonenListe.end(), Fkt);
  if (iter == PersonenListe.end() || iter == NULL) throw MatrikelNummer;
  else return *iter;
 }

//destruktor personalverwaltung
PV::~PV()
 {
  list&lt;HA*&gt;::iterator beginn = this-&gt;PersonenListe.begin();
  list&lt;HA*&gt;::iterator ende   = this-&gt;PersonenListe.end();
  for (list&lt;HA*&gt;::iterator iter=beginn; iter != ende; iter++)
   {
    delete *iter;
   }
  PersonenListe.clear();
 }

//hilfsfunktion für suche matrikelnummer
Funktor::Funktor(int MatrikelNummer)
 {
  this-&gt;matrNr = MatrikelNummer;
 }

bool Funktor::operator() (HA * ha)
 {
  S * s = dynamic_cast&lt;S*&gt;(ha);
  if (s &amp;&amp; (*s).getMatrNr()==this-&gt;matrNr)
   {
    return true;
   }
  return false;
 }

//überladen ausgabeoperator -&gt; ostream...
ostream&amp; operator&lt;&lt;(ostream&amp; out, HA * ha)
 {
  string Name = (*ha).HAName;
  string Vorname = (*ha).HAVorname;
  out&lt;&lt;Name&lt;&lt;&quot;, &quot;&lt;&lt;Vorname;
  return out;
 }
</code></pre>
<p>main:</p>
<pre><code class="language-csharp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#include &lt;iostream&gt;
#include &lt;conio&gt;
#include &lt;stdio&gt;
#include &quot;impl.cpp&quot;
#pragma hdrstop

#pragma argsused
int main(int argc, char* argv[])
 {

PV pv; //personalverwaltung schaffen

//hinzufügen studenten
pv.hinzu(&quot;Schulze&quot;,&quot;Edgar&quot;,970123);
pv.hinzu(&quot;Werder&quot;,&quot;Jana&quot;,930897);
pv.hinzu(&quot;Hartung&quot;,&quot;Mark&quot;,970235);

//hinzufügen MA (durch float automatisch)
pv.hinzu(&quot;Otto&quot;,&quot;Walter&quot;,(float)3500);
pv.hinzu(&quot;Neumeier&quot;,&quot;Regina&quot;,(float)1000);
pv.hinzu(&quot;Engelhardt&quot;,&quot;Barbara&quot;,(float)2500);

//ausgeben aller hochschulangehöriger
pv.ausgabe();

if (pv.maxMg() != NULL)
 {
  printf(&quot;\n\nmax MG : &quot;);
  cout&lt;&lt;pv.maxMg()&lt;&lt;endl&lt;&lt;endl;
 }

//suche nach matrikelnummer und rückgabe 
int MatrikelNummer = -1;
cout&lt;&lt;&quot;MatrikelNummer eingeben : &quot;;
cin&gt;&gt;MatrikelNummer;
try {
     HA * ha = pv.sucheStudent(MatrikelNummer);
     cout&lt;&lt;ha;
    }
catch (int e)
 { cout&lt;&lt;&quot;kein Eintrag!&quot;; }

 getch();
 return 0;

 }
</code></pre>
<p>wie kann ich erreichen, dass ich nicht über die matrikelnummer den namen suchen kann, sondern über den namen die matrikelnummer - muss doch irgendwie machbar sein</p>
<p>thx im voraus <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/992619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/992619</guid><dc:creator><![CDATA[Mr. Blonde]]></dc:creator><pubDate>Sun, 12 Feb 2006 20:20:46 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung on Mon, 13 Feb 2006 07:24:38 GMT]]></title><description><![CDATA[<p>Mr. Blonde schrieb:</p>
<blockquote>
<p>wie kann ich erreichen, dass ich nicht über die matrikelnummer den namen suchen kann, sondern über den namen die matrikelnummer - muss doch irgendwie machbar sein</p>
</blockquote>
<p>Indem du eine entsprechende Funktorklasse schreibst, die im Konstruktor den Namen übergeben bekommt - und dann die gefundenen Einträge nach Student castest.</p>
<p>(PS: eine kleine Bitte: verwende bitte in Zukunft cpp-Tags statt cs-Tags, dann passt das auch mit dem Syntax-Highlighting ;))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/992797</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/992797</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 13 Feb 2006 07:24:38 GMT</pubDate></item></channel></rss>