<?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[Vererbungsproblem]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe beim Vererben das Problem, dass ich nicht weiß wie ich die Unterklasse im main aufrufen kann <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
Wäre suer wenn mir da jemand helfen kann.</p>
<p>Fehlermeldung lautet class Affe has no member named Schimpanse</p>
<p>affe.h</p>
<pre><code>#ifndef AFFE_H
#define AFFE_H
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

class Affe
{
public:
    Affe(string name);
    string getname();
    void essen();
    void sitzen();
    string name;

};

#endif // AFFE_H
</code></pre>
<p>gorilla.h</p>
<pre><code>#ifndef GORILLA_H
#define GORILLA_H
#include &quot;affe.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

class Gorilla : public Affe
{
public:
    Gorilla();
    void trommelt();
    void essen();
    void sitzen();
};
#endif // GORILLA_H
</code></pre>
<p>schimpanse.h</p>
<pre><code>#ifndef SCHIMPANSE_H
#define SCHIMPANSE_H
#include &quot;affe.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

class Schimpanse: public Affe
{
public:
    Schimpanse();
    void hangelt();
    void essen();
    void sitzen();
};

#endif // SCHIMPANSE_H
</code></pre>
<p>affe.cpp</p>
<pre><code>#include &quot;affe.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

Affe::Affe(string name)
{
    this-&gt;name = name;
}

string Affe::getname(){
    return name;
}

void Affe::essen(){
    cout &lt;&lt; name &lt;&lt; &quot; isst eine Banane&quot; &lt;&lt; endl;
}

void Affe::sitzen(){
    cout &lt;&lt; name &lt;&lt; &quot; sitzt herum&quot; &lt;&lt; endl;
}
</code></pre>
<p>gorilla.cpp</p>
<pre><code>#include &quot;gorilla.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

void Gorilla::trommelt(){
    cout &lt;&lt; name &lt;&lt; &quot; trommelt&quot; &lt;&lt; endl;
}
</code></pre>
<pre><code>#include &quot;gorilla.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

void Gorilla::trommelt(){
    cout &lt;&lt; name &lt;&lt; &quot; trommelt&quot; &lt;&lt; endl;
}
</code></pre>
<p>schimpanse.cpp</p>
<pre><code>#include &quot;schimpanse.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

void Schimpanse::hangelt(){
    cout &lt;&lt; name &lt;&lt; &quot;hangelt&quot; &lt;&lt; endl;
}
</code></pre>
<p>main.cpp</p>
<pre><code>#include &lt;QCoreApplication&gt;
#include &lt;string&gt;
#include &quot;affe.h&quot;
#include &quot;schimpanse.h&quot;
#include &quot;gorilla.h&quot;
using namespace std;

int main()
{

    Affe Ursus(&quot;Ursus&quot;);
    Affe Tschita(&quot;Tschita&quot;);
    Affe George(&quot;George&quot;);

    Ursus.sitzen();
    Ursus.essen();
    George.Schimpanse.hangelt();
    Tschita.essen();

    George.essen();

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/338200/vererbungsproblem</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 18:27:11 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/338200.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 30 May 2016 16:45:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 16:45:18 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe beim Vererben das Problem, dass ich nicht weiß wie ich die Unterklasse im main aufrufen kann <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
Wäre suer wenn mir da jemand helfen kann.</p>
<p>Fehlermeldung lautet class Affe has no member named Schimpanse</p>
<p>affe.h</p>
<pre><code>#ifndef AFFE_H
#define AFFE_H
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

class Affe
{
public:
    Affe(string name);
    string getname();
    void essen();
    void sitzen();
    string name;

};

#endif // AFFE_H
</code></pre>
<p>gorilla.h</p>
<pre><code>#ifndef GORILLA_H
#define GORILLA_H
#include &quot;affe.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

class Gorilla : public Affe
{
public:
    Gorilla();
    void trommelt();
    void essen();
    void sitzen();
};
#endif // GORILLA_H
</code></pre>
<p>schimpanse.h</p>
<pre><code>#ifndef SCHIMPANSE_H
#define SCHIMPANSE_H
#include &quot;affe.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

class Schimpanse: public Affe
{
public:
    Schimpanse();
    void hangelt();
    void essen();
    void sitzen();
};

#endif // SCHIMPANSE_H
</code></pre>
<p>affe.cpp</p>
<pre><code>#include &quot;affe.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

Affe::Affe(string name)
{
    this-&gt;name = name;
}

string Affe::getname(){
    return name;
}

void Affe::essen(){
    cout &lt;&lt; name &lt;&lt; &quot; isst eine Banane&quot; &lt;&lt; endl;
}

void Affe::sitzen(){
    cout &lt;&lt; name &lt;&lt; &quot; sitzt herum&quot; &lt;&lt; endl;
}
</code></pre>
<p>gorilla.cpp</p>
<pre><code>#include &quot;gorilla.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

void Gorilla::trommelt(){
    cout &lt;&lt; name &lt;&lt; &quot; trommelt&quot; &lt;&lt; endl;
}
</code></pre>
<pre><code>#include &quot;gorilla.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

void Gorilla::trommelt(){
    cout &lt;&lt; name &lt;&lt; &quot; trommelt&quot; &lt;&lt; endl;
}
</code></pre>
<p>schimpanse.cpp</p>
<pre><code>#include &quot;schimpanse.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

void Schimpanse::hangelt(){
    cout &lt;&lt; name &lt;&lt; &quot;hangelt&quot; &lt;&lt; endl;
}
</code></pre>
<p>main.cpp</p>
<pre><code>#include &lt;QCoreApplication&gt;
#include &lt;string&gt;
#include &quot;affe.h&quot;
#include &quot;schimpanse.h&quot;
#include &quot;gorilla.h&quot;
using namespace std;

int main()
{

    Affe Ursus(&quot;Ursus&quot;);
    Affe Tschita(&quot;Tschita&quot;);
    Affe George(&quot;George&quot;);

    Ursus.sitzen();
    Ursus.essen();
    George.Schimpanse.hangelt();
    Tschita.essen();

    George.essen();

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2497477</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497477</guid><dc:creator><![CDATA[Chris9090]]></dc:creator><pubDate>Mon, 30 May 2016 16:45:18 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 16:58:49 GMT]]></title><description><![CDATA[<p>Wenn du einen Schimpansen willst, musst du auch einen anlegen und nicht einen Affen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497478</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497478</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 30 May 2016 16:58:49 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 17:12:24 GMT]]></title><description><![CDATA[<p>Und wie?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497479</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497479</guid><dc:creator><![CDATA[Chris9090]]></dc:creator><pubDate>Mon, 30 May 2016 17:12:24 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 17:24:40 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">Schimpanse george(&quot;George&quot;);

george.hangelt();
</code></pre>
<p>PS:</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;
</code></pre>
<p>brauchst du nicht immer wieder in den Headerdateien der abgeleiteten Klassen zu wiederholen, da diese ja schon über &quot;affe.h&quot; eingebunden sind.</p>
<p>Und bitte entferne</p>
<pre><code class="language-cpp">using namespace std;
</code></pre>
<p>aus deinen Headerdateien (ein globales &quot;using namespace&quot; in Headerdateien ist ganz böse).<br />
In Headerdateien direkt den Namensbereich verwenden:</p>
<pre><code class="language-cpp">std::string
</code></pre>
<p>(alternativ für Fortgeschrittenene: &quot;using std::string&quot;)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497483</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497483</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Mon, 30 May 2016 17:24:40 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 17:35:11 GMT]]></title><description><![CDATA[<p>Natürlich müssen die abgeleiteten Klassen im Konstruktor noch den Namen entgegennehmen und an den Affen weiterleiten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497486</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497486</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 30 May 2016 17:35:11 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 19:37:05 GMT]]></title><description><![CDATA[<pre><code>Schimpanse george(&quot;George&quot;); 

george.hangelt();
</code></pre>
<p>Wie kann das funktionieren, muss ich in der Schimpanse.cpp es dann gleich programmieren wie in der affe.cpp? Wenn ja was ist den der Sinn vom Vererben? Sollte doch dadurch weniger Aufwand sein...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497500</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497500</guid><dc:creator><![CDATA[Chris9090]]></dc:creator><pubDate>Mon, 30 May 2016 19:37:05 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 20:05:58 GMT]]></title><description><![CDATA[<p>frei aus dem bauch geschrieben</p>
<pre><code>class Affe
{
   public:
      Affe(const std::string &amp;n) : name(n) { }
      string getname() { return name; }
      virtual void essen() { std::cout &lt;&lt; &quot;ist mit den haenden\n&quot;; }
      void sitzen() { std::cout &lt;&lt; &quot;setzt sich\n&quot;; }

   private:
      string name;
};

class Gorilla : public Affe
{
   public:
      // using Affe::Affe; geht ab 0x11 oder 0x14. weiß net genau
      Gorilla(const std::string &amp;n) : Affe(n) {  }
      void trommelt() { std::cout &lt;&lt; &quot;trommelt\n&quot;; }
      virtual void essen() { std::cout &lt;&lt; &quot;isst mit besteck\n&quot;; }
      // void sitzen(); brauchen wir hier nicht, weil es nicht Affe::sitzen ueberschreibt
};

class Schimpanse: public Affe
{
   public:
      Schimpanse(const std::string &amp;n) : Affe(n) { }
      void hangelt() { std::cout &lt;&lt; &quot;hangelt sich durch die prärie\n&quot;; }
      //void essen(); brauchen wir nicht. isst auch mit den haenden
      //void sitzen(); sitzt wie ein affe. also bruachen wir das auch nicht
};

int main()
{

    Affe Ursus(&quot;Ursus&quot;);
    Schimpanse Tschita(&quot;Tschita&quot;);
    Gorilla George(&quot;George&quot;);

    Ursus.sitzen();
    Ursus.essen();
    George.hangelt();

    Tschita.essen();

    George.essen();

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2497503</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497503</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Mon, 30 May 2016 20:05:58 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 20:48:30 GMT]]></title><description><![CDATA[<p>Vielen Dank für deine super Antwort <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="🙂"
    /><br />
Nun ist mir schon einiges klarer.</p>
<p>Das Problem ist nur,dass ich ein Teil in der Header und den anderen Teil in der .cpp programmieren muss, so wie ich es oben rein gestellt habe. Kannst du mir evtl. noch an einer Klasse aufzeigen wie das auszusehen hat?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497511</guid><dc:creator><![CDATA[Chris9090]]></dc:creator><pubDate>Mon, 30 May 2016 20:48:30 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 21:18:02 GMT]]></title><description><![CDATA[<p>so wie du es vorher schon gemacht hast. die definition in eine cpp</p>
<pre><code>// header datei
class Affe
{
   public:
      Affe(const std::string &amp;n);
      const std::string&amp; getname() const;
      virtual void essen() const;
      void sitzen() const;

   private:
      std::string name;
};

// cpp datei
Affe::Affe(const std::string &amp;n) : name(n) 
{
}

const std::string&amp; getname() const
{
   return name;
}

void Affe::essen() const
{
   std::cout &lt;&lt; &quot;ist mit den haenden\n&quot;;
}

void Affe::sitzen() const
{
   std::cout &lt;&lt; &quot;setzt sich\n&quot;;
}
</code></pre>
<p>mit const-correctness</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497514</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497514</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Mon, 30 May 2016 21:18:02 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 21:53:32 GMT]]></title><description><![CDATA[<p>Vielen Dank habe nun das Programm so hin bekommen wie ich es wollte <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="🙂"
    /><br />
Musste nur noch string name von private in public ändern <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>
<p>Wie funktioniert das ganze eigentlich mit dem Erweiterungsprinzip anstatt mit dem Ersetzungsprinzip?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497515</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497515</guid><dc:creator><![CDATA[Chris9090]]></dc:creator><pubDate>Mon, 30 May 2016 21:53:32 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Mon, 30 May 2016 22:15:14 GMT]]></title><description><![CDATA[<p>warum in public aendern ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497516</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497516</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Mon, 30 May 2016 22:15:14 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Tue, 31 May 2016 16:21:16 GMT]]></title><description><![CDATA[<p>Da ich in Gorilla.cpp und Schimpanse.cpp auf den Namen zugreifen muss, dass du jedoch ja nicht wissen konntest.</p>
<p>Wollte nun noch die Affenart sprich Schimpanse und Gorilla hinzufügen. Hänge aber wieder an einem Problem <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /></p>
<p>Dachte man kann es so machen aber dann kommt der Fehler &quot;multipleinitalizations&quot;</p>
<pre><code>#ifndef AFFE_H
#define AFFE_H
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

class Affe
{
public:
    Affe(const string &amp;n, const string &amp;a);
    const string getname() const;
    const string getart() const;
    void essen() const;
    void sitzen() const;
    string name;
    string art;
};

#endif // AFFE_H
</code></pre>
<pre><code>#include &lt;QCoreApplication&gt;
#include &lt;string&gt;
#include &quot;affe.h&quot;
#include &quot;schimpanse.h&quot;
#include &quot;gorilla.h&quot;
#include &quot;affenforscherin.h&quot;
using namespace std;

int main()
{
    Affe Ursus (&quot;Ursus&quot;, &quot;Affe&quot;);
    Schimpanse Tschita (&quot;Tschita&quot;, &quot;Schimpanse&quot;);
    Gorilla George (&quot;George&quot;, &quot;Gorilla&quot;);

    Ursus.sitzen();
    Ursus.essen();
    Tschita.hangelt();
    Tschita.essen();
    George.trommelt();
    George.essen();

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2497564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497564</guid><dc:creator><![CDATA[Chris9090]]></dc:creator><pubDate>Tue, 31 May 2016 16:21:16 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Tue, 31 May 2016 16:36:42 GMT]]></title><description><![CDATA[<p>Du wolltest das aber nur mitteilen und den Fehler selber beheben, da du ja weder die exakte Fehlermeldung noch den Code, der dazu führt, zeigst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497565</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497565</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Tue, 31 May 2016 16:36:42 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Tue, 31 May 2016 16:53:55 GMT]]></title><description><![CDATA[<p>Chris9090 schrieb:</p>
<blockquote>
<p>Da ich in Gorilla.cpp und Schimpanse.cpp auf den Namen zugreifen muss, dass du jedoch ja nicht wissen konntest.</p>
</blockquote>
<p>Das ist keine Erklärung, denn der getter war auch vorher public.</p>
<blockquote>
<pre><code>int main()
{
    Affe Ursus (&quot;Ursus&quot;, &quot;Affe&quot;);
    Schimpanse Tschita (&quot;Tschita&quot;, &quot;Schimpanse&quot;);
    Gorilla George (&quot;George&quot;, &quot;Gorilla&quot;);
</code></pre>
</blockquote>
<p>Du hast die Art jetzt irgendwie doppelt drin, einmal als zusätzlichen String und dann noch als Typ. Das erscheint mir wenig sinnvoll.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497566</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497566</guid><dc:creator><![CDATA[wob]]></dc:creator><pubDate>Tue, 31 May 2016 16:53:55 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Tue, 31 May 2016 19:08:37 GMT]]></title><description><![CDATA[<p>Dachte man kann dies irgendwie so lösen, aber in dem Fall bin ich auf dem völlig flschen weg :/:/</p>
<p>Ich stell euch vllt am besten mal meine Aufgabenstellung rein vllt. könnt ihr es dann am besten nachvollziehen.</p>
<p><strong>Aufgabe 2: Okongo III</strong><br />
Die Affenforscherin &quot;Besine Gadegas&quot; wandert durch den Dschungel am Fluss Okongo, um das Verhalten unterschiedlicher Affenarten zu erforschen. Immer, wenn sie den Schimpansen &quot;Tschita&quot; oder den Gorilla &quot;George&quot; besucht, vollführt dieser sein typisches Verhaltensmuster und isst danach eine Banane. Implementieren Sie die Besuchssituation auf der Grundlage Ihrer Lösung der ersten Dschungelaufgabe vom letzten Übungsblatt in der folgenden Weise:<br />
Legen Sie ein neues Projekt an. Kopieren Sie in dessen Verzeichnis die Dateien der unterschiedlichen Affen aus der Aufgabe Okongo II des letzten Übungsblatts. Importieren Sie danach diese Dateien in das neue Projekt. Unter QtCreator geschieht das Importieren durch Rechtsklick auf den Projektnamen und Aufruf des Befehls Existierende Datei hinzufügen.<br />
Führen Sie dann die im Folgenden beschriebenen Ergänzungen am Projekt durch. In diesem Zusammenhang sind auch Änderungen an den kopierten Dateien erforderlich.<br />
Definieren Sie eine Klasse Affenforscherin, die über eine Methode für das Besuchen von Affen verfügt:</p>
<pre><code>void besucht(Affe &amp;a)
</code></pre>
<p>Affenforscherinnen besitzen einen Namen.<br />
Rufen Sie alle Methoden, die Handlungen der Affen betreffen, in der Methode besucht() auf und nutzen Sie dabei die dynamische Polymorphie aus.<br />
Affen können nun zusätzlich mit Hilfe einer Methode string werBinIch() Auskunft über ihre Art geben.</p>
<p>Schreiben Sie eine main(...)-Funktion, in der die Forscherin besine den Affen ursus, den Schimpansen tschita und den Gorilla george besucht. Alle Ausgaben auf die Konsole finden in den Klassen der Affenforscherin und der Affenarten und nicht in der main(...)-Funktion statt.</p>
<p><strong>Ausgabe des Programms:</strong><br />
<em>Besine besucht den Affen Ursus<br />
Ursus sitzt herum<br />
Ursus isst eine Banane<br />
Besine besucht den Schimpansen Tschita<br />
Tschita hangelt<br />
Tschita isst eine Banane<br />
Besine besucht den Gorilla George<br />
George trommelt<br />
George isst eine Banane</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497572</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497572</guid><dc:creator><![CDATA[Chris9090]]></dc:creator><pubDate>Tue, 31 May 2016 19:08:37 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Wed, 01 Jun 2016 11:07:56 GMT]]></title><description><![CDATA[<p>Kann mir niemand helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497593</guid><dc:creator><![CDATA[Chris9090]]></dc:creator><pubDate>Wed, 01 Jun 2016 11:07:56 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Wed, 01 Jun 2016 11:23:02 GMT]]></title><description><![CDATA[<p>Doch, wir könnten dir schon helfen und tun das auch gern, aber wir lösen nicht deine Hausaufgaben vollständig. Zumal es dafür auch einfacher wäre, wenn wir den gesamten Quelltext hätten.</p>
<p>Bevor du aber alles postest, versuche doch das Problem selbst zu lösen. Wenn es nicht geht, dann mach ein minimales (!) vollständiges (!) Beispiel, an dem du das Problem beschreibst.</p>
<p>Ansonsten vermute ich, dass die Aufgaben irgendwann auf das visitor-Pattern hinauslaufen sollen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497598</guid><dc:creator><![CDATA[wob]]></dc:creator><pubDate>Wed, 01 Jun 2016 11:23:02 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Wed, 01 Jun 2016 17:26:10 GMT]]></title><description><![CDATA[<p>Ok danke war wirklich zu viel verlangt von mir.<br />
Aber keine Sorge es sind nicht meine Hausaufgaben <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
<p>Also mein Problem ist ja nicht die ganze Aufgabenstellung. Mein Problem besteht darin die Affenart hinzuzufügen. Ich hab über den Konstruktor ja bereits jedem Affen einen Namen hinzugefügt und nun wollte ich dahinter noch die Affenart hinzufügen was so jedoch leider nicht klappt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>In der Aufgabenstellung steht, dass ich dazu eine Methode verwenden soll, ich weiß jedoch leider nicht wie ich das anstellen soll?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497638</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497638</guid><dc:creator><![CDATA[Chris9090]]></dc:creator><pubDate>Wed, 01 Jun 2016 17:26:10 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Wed, 01 Jun 2016 17:45:28 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>Du wolltest das aber nur mitteilen und den Fehler selber beheben, da du ja weder die exakte Fehlermeldung noch den Code, der dazu führt, zeigst?</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2497639</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497639</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 01 Jun 2016 17:45:28 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Wed, 01 Jun 2016 22:07:13 GMT]]></title><description><![CDATA[<p>Aso sorry wenn ich mich missverständlich ausgedrückt habe.</p>
<p>Ich wollte die Affenart hinzufügen aber dann kommt die Fehlermeldung <em>&quot;multiple initializiations given for base Affe&quot;</em> und <em>&quot;no matching function for callto Affe::Affe(const string &amp;)&quot;</em></p>
<p>Und nun die Frage ob das in meinem Code die komplett falsche herangehensweise ist, oder ob ich darin nur einen Fehler begangen habe?</p>
<p>Vielen Dank für eure Hilfe und sry für meine missverständliche Frage.</p>
<p>main.cpp</p>
<pre><code>#include &lt;QCoreApplication&gt;
#include &lt;string&gt;
#include &quot;affe.h&quot;
#include &quot;schimpanse.h&quot;
#include &quot;gorilla.h&quot;
#include &quot;affenforscherin.h&quot;
using namespace std;

int main()
{
    Affe Ursus (&quot;Ursus&quot;, &quot;Affe&quot;);
    Schimpanse Tschita (&quot;Tschita&quot;, &quot;Schimpanse&quot;);
    Gorilla George (&quot;George&quot;, &quot;Gorilla&quot;);

    Ursus.sitzen();
    Ursus.essen();
    Tschita.hangelt();
    Tschita.essen();
    George.trommelt();
    George.essen();

    return 0;
}
</code></pre>
<p>affe.h</p>
<pre><code>#ifndef AFFE_H
#define AFFE_H
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

class Affe
{
public:
    Affe(const string &amp;n, const string &amp;a);
    const string getname() const;
    const string getart() const;
    void essen() const;
    void sitzen() const;
    string name;
    string art;
};

#endif // AFFE_H
</code></pre>
<p>affe.cpp</p>
<pre><code>#include &quot;affe.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

Affe::Affe(const string &amp;n, const string &amp;a) : name(n), art(a)
{
}

const string Affe::getname() const{
    return name;
}

const string Affe::getart() const{
    return art;
}

void Affe::essen()const{
    cout &lt;&lt; name &lt;&lt; &quot; isst eine Banane&quot; &lt;&lt; endl;
}

void Affe::sitzen()const{
    cout &lt;&lt; name &lt;&lt; &quot; sitzt herum&quot; &lt;&lt; endl;
}
</code></pre>
<p>gorilla.h</p>
<pre><code>#ifndef GORILLA_H
#define GORILLA_H
#include &quot;affe.h&quot;

class Gorilla : public Affe
{
public:
    Gorilla(const string &amp;n, const string &amp;a);
    void trommelt() const;
};

#endif // GORILLA_H
</code></pre>
<p>gorilla.cpp</p>
<pre><code>#include &quot;gorilla.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

Gorilla::Gorilla(const string &amp;n, const string &amp;a) : Affe(n), Affe(a)
{
}

void Gorilla::trommelt() const{
    cout &lt;&lt; name &lt;&lt; &quot; trommelt&quot; &lt;&lt; endl;
}
</code></pre>
<p>schimpanse.h</p>
<pre><code>#ifndef SCHIMPANSE_H
#define SCHIMPANSE_H
#include &quot;affe.h&quot;

class Schimpanse : public Affe
{
public:
    Schimpanse(const string &amp;n, const string &amp;a);
    void hangelt() const;
};

#endif // SCHIMPANSE_H
</code></pre>
<p>schimpanse.cpp</p>
<pre><code>#include &quot;schimpanse.h&quot;
#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

Schimpanse::Schimpanse(const string &amp;n, const string &amp;a) : Affe(n), Affe(a)
{
}

void Schimpanse::hangelt() const{
    cout &lt;&lt; name &lt;&lt; &quot; hangelt&quot; &lt;&lt; endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2497662</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497662</guid><dc:creator><![CDATA[Chris9090]]></dc:creator><pubDate>Wed, 01 Jun 2016 22:07:13 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Wed, 01 Jun 2016 22:16:19 GMT]]></title><description><![CDATA[<pre><code>Schimpanse::Schimpanse(const string &amp;n, const string &amp;a) : Affe(n), Affe(a)
</code></pre>
<p>ist kreativ</p>
<pre><code>Schimpanse::Schimpanse(const string &amp;n, const string &amp;a) : Affe(n, a )
</code></pre>
<p>wird der Compiler wohl übersetzen</p>
<pre><code>Schimpanse::Schimpanse(const string &amp;n) : Affe(n, &quot;Schimpanse&quot;)
</code></pre>
<p>wäre eine Optimierung.</p>
<p>Bezüglich der Fehlermeldungen: <strong>Copy&amp;Paste!</strong></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497663</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 01 Jun 2016 22:16:19 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbungsproblem on Wed, 01 Jun 2016 22:16:52 GMT]]></title><description><![CDATA[<p>Und in der Fehlermeldung steht nicht einmal der Dateiname drin (und auch keine Zeilennummer), oder hast du das absichtlich weggelassen, damit wir es schwerer haben?</p>
<p>Dennoch: ich verrate dir, dass der Fehler in gorilla.cpp und schimpanse.cpp, jeweile in Zeile 6, liegt. Die Fehlermeldung nennt doch sogar den Grund!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2497664</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2497664</guid><dc:creator><![CDATA[wob]]></dc:creator><pubDate>Wed, 01 Jun 2016 22:16:52 GMT</pubDate></item></channel></rss>