<?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[c++ opp, Fehlermeldung bei Vererbung]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>bei meinen ersten Gehversuchen mit c++ bin ich nun leider auf ein kleines Problem gestroßen.</p>
<p>Ich habe 4 Dateien mit 2 Klassen und der main Funktion.</p>
<p>Will ich das Programm nun ausführen kommt folgende Fehlermeldung <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
<p>7 G:\PortableApps\Dev-CppPortable\Projekte\test\man.h:1, from main.cpp In file included from man.h:1, from main.cpp<br />
7 G:\PortableApps\Dev-CppPortable\Projekte\test\main.cpp from main.cpp<br />
1 G:\PortableApps\Dev-CppPortable\Projekte\test\human.h redefinition of <code>class Human' 1 G:\\PortableApps\\Dev-CppPortable\\Projekte\\test\\human.h previous definition of</code>class Human'<br />
G:\PortableApps\Dev-CppPortable\Projekte\test\Makefile.win [Build Error] [main.o] Error 1</p>
<p>Leider verstehe ich das das Problem nicht. Vielleicht habe ich die Schreibweise<br />
nicht richtig verstanden.</p>
<p>Könnt ihr mir da vielleicht helfen?</p>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;string&gt; 

#include &quot;human.h&quot; //klasse human wird geladen
#include &quot;man.h&quot; //klasse man wird geladen

using namespace std;

int main(void)
{

    Man stephan();

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>human.h</p>
<pre><code class="language-cpp">class Human {

   public: //variablen
      char name;
      int  age;
      int  height;	
      int  weight;

   public: //methoden
           Human(void); //Konstruktormethode
           Human(int age, int height, int weight); //Konstruktormethode

           ~Human(); //Destruktor

      int  GetAge(void) const;
      void SetAge(int age);

      int  GetHeight(void) const;
      void SetHeight(int height);

      int  GetWeight(void) const;
      void SetWeight(int weight);

};
</code></pre>
<p>human.cpp</p>
<pre><code class="language-cpp">#include &quot;human.h&quot;

Human::Human(int age, int height, int weight) { //Konstruktor methode
    this-&gt;SetAge(age);
    this-&gt;SetHeight(height);
    this-&gt;SetWeight(weight);
}

Human::~Human() {
}

int Human::GetAge(void) const {
    return this-&gt;age;
}
void Human::SetAge(int age) {
   this-&gt;age = age;
}

int Human::GetHeight(void) const {
   return this-&gt;height;
}
void Human::SetHeight(int height) {
   this-&gt;height = height;
}

int Human::GetWeight(void) const {
   return this-&gt;weight;
}
void Human::SetWeight(int weight) {
   this-&gt;weight = weight;
}
</code></pre>
<p>man.h</p>
<pre><code class="language-cpp">#include &quot;human.h&quot;

class Man : public Human {

      public:
           Man(void); //Konstruktormethode
           ~Man(); //Destruktormethode

};
</code></pre>
<p>man.cpp</p>
<pre><code class="language-cpp">#include &quot;man.h&quot;

Man::Man() {
}
Man::~Man() {
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/249604/c-opp-fehlermeldung-bei-vererbung</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 11:05:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/249604.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Sep 2009 16:16:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to c++ opp, Fehlermeldung bei Vererbung on Wed, 09 Sep 2009 16:16:07 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>bei meinen ersten Gehversuchen mit c++ bin ich nun leider auf ein kleines Problem gestroßen.</p>
<p>Ich habe 4 Dateien mit 2 Klassen und der main Funktion.</p>
<p>Will ich das Programm nun ausführen kommt folgende Fehlermeldung <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
<p>7 G:\PortableApps\Dev-CppPortable\Projekte\test\man.h:1, from main.cpp In file included from man.h:1, from main.cpp<br />
7 G:\PortableApps\Dev-CppPortable\Projekte\test\main.cpp from main.cpp<br />
1 G:\PortableApps\Dev-CppPortable\Projekte\test\human.h redefinition of <code>class Human' 1 G:\\PortableApps\\Dev-CppPortable\\Projekte\\test\\human.h previous definition of</code>class Human'<br />
G:\PortableApps\Dev-CppPortable\Projekte\test\Makefile.win [Build Error] [main.o] Error 1</p>
<p>Leider verstehe ich das das Problem nicht. Vielleicht habe ich die Schreibweise<br />
nicht richtig verstanden.</p>
<p>Könnt ihr mir da vielleicht helfen?</p>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;string&gt; 

#include &quot;human.h&quot; //klasse human wird geladen
#include &quot;man.h&quot; //klasse man wird geladen

using namespace std;

int main(void)
{

    Man stephan();

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>human.h</p>
<pre><code class="language-cpp">class Human {

   public: //variablen
      char name;
      int  age;
      int  height;	
      int  weight;

   public: //methoden
           Human(void); //Konstruktormethode
           Human(int age, int height, int weight); //Konstruktormethode

           ~Human(); //Destruktor

      int  GetAge(void) const;
      void SetAge(int age);

      int  GetHeight(void) const;
      void SetHeight(int height);

      int  GetWeight(void) const;
      void SetWeight(int weight);

};
</code></pre>
<p>human.cpp</p>
<pre><code class="language-cpp">#include &quot;human.h&quot;

Human::Human(int age, int height, int weight) { //Konstruktor methode
    this-&gt;SetAge(age);
    this-&gt;SetHeight(height);
    this-&gt;SetWeight(weight);
}

Human::~Human() {
}

int Human::GetAge(void) const {
    return this-&gt;age;
}
void Human::SetAge(int age) {
   this-&gt;age = age;
}

int Human::GetHeight(void) const {
   return this-&gt;height;
}
void Human::SetHeight(int height) {
   this-&gt;height = height;
}

int Human::GetWeight(void) const {
   return this-&gt;weight;
}
void Human::SetWeight(int weight) {
   this-&gt;weight = weight;
}
</code></pre>
<p>man.h</p>
<pre><code class="language-cpp">#include &quot;human.h&quot;

class Man : public Human {

      public:
           Man(void); //Konstruktormethode
           ~Man(); //Destruktormethode

};
</code></pre>
<p>man.cpp</p>
<pre><code class="language-cpp">#include &quot;man.h&quot;

Man::Man() {
}
Man::~Man() {
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1775426</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775426</guid><dc:creator><![CDATA[squee]]></dc:creator><pubDate>Wed, 09 Sep 2009 16:16:07 GMT</pubDate></item><item><title><![CDATA[Reply to c++ opp, Fehlermeldung bei Vererbung on Wed, 09 Sep 2009 16:33:19 GMT]]></title><description><![CDATA[<p>Deine Header brauchen <a href="http://en.wikipedia.org/wiki/Include_guard" rel="nofollow">Include Guards</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775432</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775432</guid><dc:creator><![CDATA[Registrierter Troll]]></dc:creator><pubDate>Wed, 09 Sep 2009 16:33:19 GMT</pubDate></item><item><title><![CDATA[Reply to c++ opp, Fehlermeldung bei Vererbung on Wed, 09 Sep 2009 16:42:38 GMT]]></title><description><![CDATA[<p>btw:</p>
<p><code>int main(void)</code> -&gt; <code>int main()</code></p>
<p><code>Man stephan();</code> -&gt; <code>Man stephan;</code></p>
<p><code>return EXIT_SUCCESS;</code> -&gt; kannst du auch weglassen</p>
<pre><code class="language-cpp">public: //variablen
      char name;
      int  age;
      int  height;	
      int  weight;
</code></pre>
<p>1. wieso public?<br />
2. char name macht bestimmt was ganz anderes, als du willst : D<br />
versuchs mal mit std::string name und ganz oben noch #include &lt;string&gt;</p>
<p><code>Human(void)</code> -&gt; <code>Human()</code> - hast du übrigens vergessen zu implementieren</p>
<p><code>~Human();</code> brauchst du nicht - aber wenn du Polymorphie willst, solltest du überlegen, dort <code>virtual ~Human() {}</code> zu schreiben</p>
<pre><code class="language-cpp">Human::Human(int age, int height, int weight) { //Konstruktor methode
    this-&gt;SetAge(age);
    this-&gt;SetHeight(height);
    this-&gt;SetWeight(weight);
}
</code></pre>
<p>1.) Initialisierungsliste<br />
2.) wieso jedes mal this-&gt; ?</p>
<pre><code class="language-cpp">#include &quot;human.h&quot;

class Man : public Human {

      public:
           Man(void); //Konstruktormethode
           ~Man(); //Destruktormethode

};

Man::Man() {
}
Man::~Man() {
}
</code></pre>
<p>wenn du das so lassen möchtest, dann reicht es auch so:</p>
<pre><code class="language-cpp">#include &quot;human.h&quot;

class Man : public Human {};
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1775437</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1775437</guid><dc:creator><![CDATA[unskilled @logged-off]]></dc:creator><pubDate>Wed, 09 Sep 2009 16:42:38 GMT</pubDate></item></channel></rss>