<?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 Deklaration bei C++]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich hänge an einem doofen Problem und komme nicht weiter. Ich habe zwei Klassen, die sich gegenseitig aufrufen und bekomme dazu folgenden Fehler:</p>
<p>auftrag.h:18:19: error: ‘Kunde’ has not been declared<br />
auftrag.h:19:5: error: ‘Kunde’ does not name a type<br />
auftrag.h:23:5: error: ‘Kunde’ does not name a type</p>
<p>Bei folgendem Quellcode:</p>
<p>auftrag.h</p>
<pre><code class="language-cpp">#ifndef AUFTRAG_H
#define	AUFTRAG_H

#include &lt;string&gt;
#include &lt;vector&gt;
#include &quot;kunde.h&quot;

using std::string;

class Auftrag {
public:
    Auftrag(string s);
    ~Auftrag( );

    void print();
    const string&amp; getID();

    void setKunde(Kunde* k);
    Kunde* getKunde();
    void delPtrAusKunde();
private:
    string id;
    Kunde* Kunde;
};

#endif
</code></pre>
<p>kunde.h</p>
<pre><code class="language-cpp">#ifndef KUNDE_H
#define	KUNDE_H

#include &lt;string&gt;
#include &lt;vector&gt;
#include &quot;auftrag.h&quot;

using std::string;
using std::vector;

class Kunde {
public:
    Kunde(string s);
    ~Kunde();

    void print();
    const string&amp; getName();

    void addAuftrag(Auftrag *a);
    vector&lt;Auftrag*&gt;&amp; getAuftraege();
    void cancelAuftrag(Auftrag *a);
private:
    string name;
    vector&lt;Auftrag*&gt; vMyAuftr;
};

#endif
</code></pre>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;kunde.h&quot;
#include &quot;auftrag.h&quot;

using namespace std;

int main() {

    return 0;
}
</code></pre>
<p>Ich hab doch beide Deklarationen bei den h-Dateien nochmals eingebunden, aber bekomme trotzdem den Fehler ... Kann mir jemand helfen?</p>
<p>Danke schonmal! Gruß Marc</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/297459/problem-mit-deklaration-bei-c</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 11:03:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/297459.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Dec 2011 11:24:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Thu, 29 Dec 2011 11:24:25 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich hänge an einem doofen Problem und komme nicht weiter. Ich habe zwei Klassen, die sich gegenseitig aufrufen und bekomme dazu folgenden Fehler:</p>
<p>auftrag.h:18:19: error: ‘Kunde’ has not been declared<br />
auftrag.h:19:5: error: ‘Kunde’ does not name a type<br />
auftrag.h:23:5: error: ‘Kunde’ does not name a type</p>
<p>Bei folgendem Quellcode:</p>
<p>auftrag.h</p>
<pre><code class="language-cpp">#ifndef AUFTRAG_H
#define	AUFTRAG_H

#include &lt;string&gt;
#include &lt;vector&gt;
#include &quot;kunde.h&quot;

using std::string;

class Auftrag {
public:
    Auftrag(string s);
    ~Auftrag( );

    void print();
    const string&amp; getID();

    void setKunde(Kunde* k);
    Kunde* getKunde();
    void delPtrAusKunde();
private:
    string id;
    Kunde* Kunde;
};

#endif
</code></pre>
<p>kunde.h</p>
<pre><code class="language-cpp">#ifndef KUNDE_H
#define	KUNDE_H

#include &lt;string&gt;
#include &lt;vector&gt;
#include &quot;auftrag.h&quot;

using std::string;
using std::vector;

class Kunde {
public:
    Kunde(string s);
    ~Kunde();

    void print();
    const string&amp; getName();

    void addAuftrag(Auftrag *a);
    vector&lt;Auftrag*&gt;&amp; getAuftraege();
    void cancelAuftrag(Auftrag *a);
private:
    string name;
    vector&lt;Auftrag*&gt; vMyAuftr;
};

#endif
</code></pre>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;kunde.h&quot;
#include &quot;auftrag.h&quot;

using namespace std;

int main() {

    return 0;
}
</code></pre>
<p>Ich hab doch beide Deklarationen bei den h-Dateien nochmals eingebunden, aber bekomme trotzdem den Fehler ... Kann mir jemand helfen?</p>
<p>Danke schonmal! Gruß Marc</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2161744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161744</guid><dc:creator><![CDATA[meGa]]></dc:creator><pubDate>Thu, 29 Dec 2011 11:24:25 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Thu, 29 Dec 2011 11:40:51 GMT]]></title><description><![CDATA[<p>Ich denke du brauchst in auftrag.h eine Forward Declaration fuer die Klasse Kunde, damit der Compiler weiss, dass Kunde eine Klasse ist, die sich irgendwo befindet.</p>
<pre><code class="language-cpp">#ifndef AUFTRAG_H 
#define    AUFTRAG_H 

#include &lt;string&gt; 
#include &lt;vector&gt; 
#include &quot;kunde.h&quot; 

using std::string;

class Kunde; // Forward Declaration

class Auftrag { 
public: 
    Auftrag(string s); 
    ~Auftrag( ); 

    void print(); 
    const string&amp; getID(); 

    void setKunde(Kunde* k); 
    Kunde* getKunde(); 
    void delPtrAusKunde(); 
private: 
    string id; 
    Kunde* Kunde; 
}; 

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2161750</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161750</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Thu, 29 Dec 2011 11:40:51 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Thu, 29 Dec 2011 11:43:09 GMT]]></title><description><![CDATA[<p>Gegenseitiges Einbinden von Headern geht immer schief. Du brauchst eine Vorwärtsdeklaration:</p>
<pre><code class="language-cpp">#ifndef AUFTRAG_H
#define    AUFTRAG_H

#include &lt;string&gt;
#include &lt;vector&gt;

class Kunde;

using std::string;

class Auftrag {
public:
    Auftrag(string s);
    ~Auftrag( );

    void print();
    const string&amp; getID();

    void setKunde(Kunde* k);
    Kunde* getKunde();
    void delPtrAusKunde();
private:
    string id;
    Kunde* Kunde;
};

#endif
</code></pre>
<pre><code class="language-cpp">#ifndef KUNDE_H
#define    KUNDE_H

#include &lt;string&gt;
#include &lt;vector&gt;

class Auftrag;

using std::string;
using std::vector;

class Kunde {
public:
    Kunde(string s);
    ~Kunde();

    void print();
    const string&amp; getName();

    void addAuftrag(Auftrag *a);
    vector&lt;Auftrag*&gt;&amp; getAuftraege();
    void cancelAuftrag(Auftrag *a);
private:
    string name;
    vector&lt;Auftrag*&gt; vMyAuftr;
};

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2161751</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161751</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 29 Dec 2011 11:43:09 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Thu, 29 Dec 2011 12:29:02 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>vielen Dank schonmal, aber das hatte ich auch versucht und da kommt folgender Fehler:</p>
<p>In file included from main.cpp:3:0:<br />
auftrag.h:24:12: error: declaration of ‘Kunde* Auftrag::Kunde’<br />
kunde.h:13:13: error: changes meaning of ‘Kunde’ from ‘class Kunde’</p>
<p><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>
]]></description><link>https://www.c-plusplus.net/forum/post/2161765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161765</guid><dc:creator><![CDATA[meGa]]></dc:creator><pubDate>Thu, 29 Dec 2011 12:29:02 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Thu, 29 Dec 2011 12:39:50 GMT]]></title><description><![CDATA[<pre><code>Kunde* Kunde;
</code></pre>
<p>Du deklarierst ein Object Kunde mit Typ Zeiger auf Kunde - doppelte Bedeutung des Bezeichners &quot;Kunde&quot;. Nenn das Objekt einfach anders.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2161774</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161774</guid><dc:creator><![CDATA[arghonaut]]></dc:creator><pubDate>Thu, 29 Dec 2011 12:39:50 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Thu, 29 Dec 2011 12:49:56 GMT]]></title><description><![CDATA[<p>Super, vielen Dank <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/2161781</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161781</guid><dc:creator><![CDATA[meGa]]></dc:creator><pubDate>Thu, 29 Dec 2011 12:49:56 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Thu, 29 Dec 2011 13:07:12 GMT]]></title><description><![CDATA[<p>Was für ein grässliches Denglisch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2161787</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161787</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Thu, 29 Dec 2011 13:07:12 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Thu, 29 Dec 2011 13:31:04 GMT]]></title><description><![CDATA[<p>Ich hab noch ein weites Problem und zwar baue ich gerade die Methode &quot;print&quot; von Kunde:</p>
<pre><code class="language-cpp">void Kunde::print() {
    cout &lt;&lt; &quot;Kunde: &quot; &lt;&lt; name &lt;&lt; endl &lt;&lt; &quot;Auftraege: &quot;;
    for(int i = 0; i &lt; vMyAuftr.size(); i++)
        cout &lt;&lt; (*(vMyAuftr.at(i))).getID() &lt;&lt; &quot; &quot;;
}
</code></pre>
<p>Da bekomm ich folgenden Fehler:</p>
<p>kunde.h:46:36: error: invalid use of incomplete type ‘struct Auftrag’<br />
kunde.h:7:7: error: forward declaration of ‘struct Auftrag’</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2161799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161799</guid><dc:creator><![CDATA[meGa]]></dc:creator><pubDate>Thu, 29 Dec 2011 13:31:04 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Thu, 29 Dec 2011 13:43:04 GMT]]></title><description><![CDATA[<p>In der Implementierung reicht die Vorwärtsdeklaration nicht mehr. Da musst du dann wirklich die auftrag.h einbinden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2161806</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161806</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 29 Dec 2011 13:43:04 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Thu, 29 Dec 2011 13:46:46 GMT]]></title><description><![CDATA[<p>Klar, in kunde.h hast du (wg. Vermeidung zyklischer Einbindung der Header) nur eine Forward Declaration. Um &quot;Auftrag&quot; verwenden zu können, brauchst du aber die Definition der Klasse, die du erst mit dem include bekommst.<br />
Um nicht wieder in zyklisches einbinden zu laufen, legst du eine Datei &quot;kunde.cpp&quot; an, in die du die Definition von Kunde::print() vornimmst. Dort kannst du gefahrlos kunde.h und auftrag.h einbinden.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19375">@SeppJ</a>: er implementiert gerade in kunde.h (laut Fehlermeldung)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2161810</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161810</guid><dc:creator><![CDATA[arghonaut]]></dc:creator><pubDate>Thu, 29 Dec 2011 13:46:46 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Fri, 30 Dec 2011 20:54:13 GMT]]></title><description><![CDATA[<p>Evtl. könnte man bei den Funktions(deklarationen)auch besser Referenzen statt Zeiger verwenden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162269</guid><dc:creator><![CDATA[redrew99]]></dc:creator><pubDate>Fri, 30 Dec 2011 20:54:13 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Fri, 30 Dec 2011 21:09:41 GMT]]></title><description><![CDATA[<p>redrew99 schrieb:</p>
<blockquote>
<p>Evtl. könnte man bei den Funktions(deklarationen)auch besser Referenzen statt Zeiger verwenden?</p>
</blockquote>
<p>Evtl. könnte man bei den Funktions(deklarationen)auch besser die Zeiger lassen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162271</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 30 Dec 2011 21:09:41 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Fri, 30 Dec 2011 21:22:45 GMT]]></title><description><![CDATA[<p>mal ganz ehrlich: referenzen in klassen verwenden? das hab ich nie gebraucht bis jetzt, ist auch recht unflexibel aus meiner sicht. klar es gibt sicherlich das ein oder andere anwendungsgebiet, aber da gibts bessere alternativen.</p>
<p>und zum zeiger: da gibts wahrlich bessere alternativen in diesem fall, und sei es nur ein smart pointer aus der STL. aber am besten ist immer noch, gar kein zeiger</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162275</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162275</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 30 Dec 2011 21:22:45 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Fri, 30 Dec 2011 21:32:27 GMT]]></title><description><![CDATA[<p>Er meinte sicherlich bei</p>
<pre><code class="language-cpp">void setKunde(Kunde* k);
</code></pre>
<p>mit dem Gebetsmühlenargument, da der Kunde nicht 0 sein darf, müsse man das so per Referenz anzeigen.</p>
<pre><code class="language-cpp">void setKunde(Kunde&amp; k);
</code></pre>
<p>Anderenfalls müsse man im Code von setKunde gegen 0 prüfen.<br />
Das ist jedesmal falsch, wenn dieses Argument kommt.</p>
<p>Und diesmal besonders</p>
<pre><code class="language-cpp">bla.setKunde(*new Kunde(...));
</code></pre>
<p>:xmas2: :xmas2:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162279</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162279</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 30 Dec 2011 21:32:27 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Deklaration bei C++ on Fri, 30 Dec 2011 21:59:33 GMT]]></title><description><![CDATA[<p>oh mist, kann auch sein. hab mir den quellcode nicht aufmerksam angeguckt -.-'</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162285</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162285</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 30 Dec 2011 21:59:33 GMT</pubDate></item></channel></rss>