<?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[Problem mit Vorwärtsdeklaration]]></title><description><![CDATA[<p>Hey Leute habe folgenden Code:</p>
<p>classGegner.h</p>
<pre><code class="language-cpp">#ifndef CLASSGEGNER_H_INCLUDED
#define CLASSGEGNER_H_INCLUDED

#include &lt;string&gt;

class Gegner
{
    public:
        Gegner( std::string name, int gesundheit, int ruestung, int schnelligkeit );
        ~Gegner();
        std::string getName() const { return itsName; }
        void setName( std::string name );
        int getGesundheit() const { return itsGesundheit; }
        void setGesundheit( int gesundheit );
        int getRuestung() const { return itsRuestung; }
        void setRuestung( int ruestung );
        int getSchnelligkeit() const { return itsSchnelligkeit; )
        void setSchnelligkeit( int schnelligkeit );

    private:
        std::string itsName;
        int itsGesundheit;
        int itsRuestung;
        int itsSchnelligkeit;
};

class StaerkeGegner : public Gegner
{
    public:
        StaerkeGegner( std::string name, int gesundheit, int ruestung, int schnelligkeit, int staerke );
        ~StaerkeGegner();
        int getStaerke() const { return itsStaerke; }
        void setStaerke( int staerke );

    private:
        int itsStaerke;
};

class ZauberGegner : public Gegner
{
    public:
        ZauberGegner( std::string name, int gesundheit, int ruestung, int schnelligkeit, int zauberfaehigkeit );
        ~ZauberGegner();
        int getZauberfaehigkeit() const { return itsZauberfaehigkeit; }
        void setZauberfaehigkeit( int zauberfaehigkeit );

    private:
        int itsZauberfaehigkeit;
};

#endif // CLASSGEGNER_H_INCLUDED
</code></pre>
<p>classGegner.cpp</p>
<pre><code class="language-cpp">#include &quot;classGegner.h&quot;
#include &lt;string&gt;

using namespace std;

Gegner::Gegner( string name, int gesundheit, int ruestung, int schnelligkeit ):
    itsName( name ), itsGesundheit( gesundheit ), itsRuestung( ruestung), itsSchnelligkeit( schnelligkeit )
{
}

Gegner::~Gegner()
{
}

void Gegner::setName( string name )
{
    itsName = name;
}

void Gegner::setGesundheit( int gesundheit )
{
    itsGesundheit = gesundheit;
}

void Gegner::setRuestung( int ruestung )
{
    itsRuestung = ruestung;
}

void Gegner::setSchnelligkeit( int schnelligkeit )
{
    itsSchnelligkeit = schnelligkeit;
}

StaerkeGegner::StaerkeGegner( string name, int gesundheit, int ruestung, int schnelligkeit, int staerke ):
    itsStaerke( staerke )
{
    Gegner( name, gesundheit, ruestung, schnelligkeit );
}

StaerkeGegner::~StaerkeGegner()
{
}

void StaerkeGegner::setStaerke( int staerke )
{
    itsStaerke = staerke;
}

ZauberGegner::ZauberGegner( string name, int gesundheit, int ruestung, int schnelligkeit, int zauberfaehigkeit ):
    itsZauberfaehigkeit( zauberfaehigkeit )
{
    Gegner( name, gesundheit, ruestung, schnelligkeit );
}

ZauberGegner::~ZauberGegner()
{
}

void ZauberGegner::setZauberfaehigkeit( int zauberfaehigkeit )
{
    itsZauberfaehigkeit = zauberfaehigkeit;
}
</code></pre>
<p>Ich bekomme sehr viele Fehlermeldungen, ich denke jedoch, die beiden an denen es liegt sind diese hier:<br />
classGegner.h Zeile 28 invalid use of undefined typ gegner<br />
classGegner.h&quot; Zeile 7 forward declaration of type class gegner<br />
classGegner.h&quot; Zeile 40 invalid use of type class gegner</p>
<p>die anderen fehlermeldungen beziehen sich auf die .cpp datei und hängen vermute ich mit den fehlern zusammen.</p>
<p>Ich kapiere es jedoch nicht, denn ich deklariere ja gegner bevor ich die davon abgeleiteten klassen deklariere.</p>
<p>Hoffe ihr könnt mir wieder einmal Helfen=)</p>
<p>Danke schonmal</p>
<p>Gruß fr33G</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/261639/problem-mit-vorwärtsdeklaration</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 03:48:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/261639.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 21 Feb 2010 20:49:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Vorwärtsdeklaration on Mon, 22 Feb 2010 16:43:36 GMT]]></title><description><![CDATA[<p>Hey Leute habe folgenden Code:</p>
<p>classGegner.h</p>
<pre><code class="language-cpp">#ifndef CLASSGEGNER_H_INCLUDED
#define CLASSGEGNER_H_INCLUDED

#include &lt;string&gt;

class Gegner
{
    public:
        Gegner( std::string name, int gesundheit, int ruestung, int schnelligkeit );
        ~Gegner();
        std::string getName() const { return itsName; }
        void setName( std::string name );
        int getGesundheit() const { return itsGesundheit; }
        void setGesundheit( int gesundheit );
        int getRuestung() const { return itsRuestung; }
        void setRuestung( int ruestung );
        int getSchnelligkeit() const { return itsSchnelligkeit; )
        void setSchnelligkeit( int schnelligkeit );

    private:
        std::string itsName;
        int itsGesundheit;
        int itsRuestung;
        int itsSchnelligkeit;
};

class StaerkeGegner : public Gegner
{
    public:
        StaerkeGegner( std::string name, int gesundheit, int ruestung, int schnelligkeit, int staerke );
        ~StaerkeGegner();
        int getStaerke() const { return itsStaerke; }
        void setStaerke( int staerke );

    private:
        int itsStaerke;
};

class ZauberGegner : public Gegner
{
    public:
        ZauberGegner( std::string name, int gesundheit, int ruestung, int schnelligkeit, int zauberfaehigkeit );
        ~ZauberGegner();
        int getZauberfaehigkeit() const { return itsZauberfaehigkeit; }
        void setZauberfaehigkeit( int zauberfaehigkeit );

    private:
        int itsZauberfaehigkeit;
};

#endif // CLASSGEGNER_H_INCLUDED
</code></pre>
<p>classGegner.cpp</p>
<pre><code class="language-cpp">#include &quot;classGegner.h&quot;
#include &lt;string&gt;

using namespace std;

Gegner::Gegner( string name, int gesundheit, int ruestung, int schnelligkeit ):
    itsName( name ), itsGesundheit( gesundheit ), itsRuestung( ruestung), itsSchnelligkeit( schnelligkeit )
{
}

Gegner::~Gegner()
{
}

void Gegner::setName( string name )
{
    itsName = name;
}

void Gegner::setGesundheit( int gesundheit )
{
    itsGesundheit = gesundheit;
}

void Gegner::setRuestung( int ruestung )
{
    itsRuestung = ruestung;
}

void Gegner::setSchnelligkeit( int schnelligkeit )
{
    itsSchnelligkeit = schnelligkeit;
}

StaerkeGegner::StaerkeGegner( string name, int gesundheit, int ruestung, int schnelligkeit, int staerke ):
    itsStaerke( staerke )
{
    Gegner( name, gesundheit, ruestung, schnelligkeit );
}

StaerkeGegner::~StaerkeGegner()
{
}

void StaerkeGegner::setStaerke( int staerke )
{
    itsStaerke = staerke;
}

ZauberGegner::ZauberGegner( string name, int gesundheit, int ruestung, int schnelligkeit, int zauberfaehigkeit ):
    itsZauberfaehigkeit( zauberfaehigkeit )
{
    Gegner( name, gesundheit, ruestung, schnelligkeit );
}

ZauberGegner::~ZauberGegner()
{
}

void ZauberGegner::setZauberfaehigkeit( int zauberfaehigkeit )
{
    itsZauberfaehigkeit = zauberfaehigkeit;
}
</code></pre>
<p>Ich bekomme sehr viele Fehlermeldungen, ich denke jedoch, die beiden an denen es liegt sind diese hier:<br />
classGegner.h Zeile 28 invalid use of undefined typ gegner<br />
classGegner.h&quot; Zeile 7 forward declaration of type class gegner<br />
classGegner.h&quot; Zeile 40 invalid use of type class gegner</p>
<p>die anderen fehlermeldungen beziehen sich auf die .cpp datei und hängen vermute ich mit den fehlern zusammen.</p>
<p>Ich kapiere es jedoch nicht, denn ich deklariere ja gegner bevor ich die davon abgeleiteten klassen deklariere.</p>
<p>Hoffe ihr könnt mir wieder einmal Helfen=)</p>
<p>Danke schonmal</p>
<p>Gruß fr33G</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859281</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859281</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Mon, 22 Feb 2010 16:43:36 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Vorwärtsdeklaration on Sun, 21 Feb 2010 21:35:42 GMT]]></title><description><![CDATA[<p>In Zeile 17, hast du eine runde Klammer zu gemacht, da muss aber eine geschweifte Klammer zu hin. Sehr unglückliche Fehlermeldung, die der Compiler da raus macht. Mit der richtigen Klammerung funktioniert alles, zumindest in der Header-Datei, die cpp habe ich jetzt nicht getestet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859294</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 21 Feb 2010 21:35:42 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Vorwärtsdeklaration on Sun, 21 Feb 2010 22:19:57 GMT]]></title><description><![CDATA[<p>Mach mal in Gegner den Destruktor virtual.<br />
Und in der .cpp</p>
<pre><code class="language-cpp">StaerkeGegner::StaerkeGegner( string name, int gesundheit, int  ruestung, int schnelligkeit, int staerke ):
    itsStaerke( staerke )
{
    Gegner( name, gesundheit, ruestung, schnelligkeit );
}
</code></pre>
<p>sollte doch eher</p>
<pre><code class="language-cpp">StaerkeGegner::StaerkeGegner( string name, int gesundheit, int  ruestung, int schnelligkeit, int staerke ):
    Gegner( name, gesundheit, ruestung, schnelligkeit ),
    itsStaerke( staerke )
{
}
</code></pre>
<p>heißen, oder? (Basisinitialisierung)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859305</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859305</guid><dc:creator><![CDATA[bratmaxe]]></dc:creator><pubDate>Sun, 21 Feb 2010 22:19:57 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Vorwärtsdeklaration on Mon, 22 Feb 2010 15:45:52 GMT]]></title><description><![CDATA[<p>Hey Danke an euch beide für die schnelle und sehr hilfreichen Antworten.</p>
<p>Hab beides geändert, uns nun läufts=)</p>
<p>Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859612</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Mon, 22 Feb 2010 15:45:52 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Vorwärtsdeklaration on Mon, 22 Feb 2010 16:46:17 GMT]]></title><description><![CDATA[<p>Soo Leute, hätte doch nochmal ne Frage, passt zwar net direkt unter den Threadnamen, aber da hier schon die Quelldatein sind post ichs grad hier zu.</p>
<p>Kann ich irgendwie im Programm abfragen ob ein Zeiger</p>
<pre><code class="language-cpp">Gegner* myGegner
</code></pre>
<p>ein Zeiger auf ein<br />
ZauberGegner<br />
oder auf ein StaerkeGegner ist?</p>
<p>also so auf die art</p>
<pre><code class="language-cpp">if( myGegner == ZauberGegner* )
//do something
elsle if( myGegner == StaerkeGegner* )
// do something
</code></pre>
<p>Danke schonmal=)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859664</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859664</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Mon, 22 Feb 2010 16:46:17 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Vorwärtsdeklaration on Mon, 22 Feb 2010 16:49:48 GMT]]></title><description><![CDATA[<p>Das geht zwar auch, aber das Stichwort das du suchst ist <em>Polymorphie</em>. Damit geht das nochmal ein ganzes Stück eleganter als das was du vor hast. Schlag das mal in deinem Lehrbuch/Google nach.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859666</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859666</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 22 Feb 2010 16:49:48 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Vorwärtsdeklaration on Mon, 22 Feb 2010 16:50:12 GMT]]></title><description><![CDATA[<p>dynamic_cast <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859667</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859667</guid><dc:creator><![CDATA[dynamic_cast&amp;lt;&amp;gt;]]></dc:creator><pubDate>Mon, 22 Feb 2010 16:50:12 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Vorwärtsdeklaration on Mon, 22 Feb 2010 16:54:58 GMT]]></title><description><![CDATA[<p>Wenn so etwas notwendig ist, stimmt was am Design nicht <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="😉"
    /><br />
Ich nehme an, du willst mit dem Gegner interagieren. Z.B. soll dir der Gegner Schaden zufügen.<br />
Dann gib Gegner ne Virtuelle Methode, die du aufrufst.<br />
Z.B. sowas:</p>
<pre><code class="language-cpp">class Player {
};

class Gegner {
    virtual void damagePlayer( Player* )=0;
}

class RitterGegner : public Gegner {
    void damagePlayer( Player *p ) {
        p-&gt;chopHead();
    }
};

class ZauberGegner : public Gegner {
    void damagePlayer( Player* p ) {
        randomWizTransform(p);
    }
};
</code></pre>
<p>Ich hoffe es ist klar worauf ich hinaus will <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/1859671</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859671</guid><dc:creator><![CDATA[l&#x27;abra d&#x27;or]]></dc:creator><pubDate>Mon, 22 Feb 2010 16:54:58 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Vorwärtsdeklaration on Mon, 22 Feb 2010 16:57:03 GMT]]></title><description><![CDATA[<p>dynamic_cast&lt;&gt; schrieb:</p>
<blockquote>
<p>dynamic_cast <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
</blockquote>
<p>Was oberträge ist und die Abfrage des return nach Hinzufügen einer neuen Klasse erweitert werden muss. Dann am besten noch in ner falschen Reihenfolge (Basisklasse vor abgeleiteter Klasse), und schon ist die Kacke am Dampfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859672</guid><dc:creator><![CDATA[l&#x27;abra d&#x27;or]]></dc:creator><pubDate>Mon, 22 Feb 2010 16:57:03 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Vorwärtsdeklaration on Mon, 22 Feb 2010 20:00:06 GMT]]></title><description><![CDATA[<p>Ok, danke schön.<br />
Weiß grad auch net wieso ich so umständlich gedacht habe...<br />
Ich habe ja mittlerweile die Klasse auch schon bissel geändert gehabt mit virtuellen Methoden.<br />
Aber mein Problem wollt ich wohl wieder mal zu umständlich lösen;-)</p>
<p>Auf jeden Fall mal danke=)</p>
<p>Und ja ich weiß wo du drauf hinaus willst <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/1859758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859758</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Mon, 22 Feb 2010 20:00:06 GMT</pubDate></item></channel></rss>