<?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 Headern]]></title><description><![CDATA[<p>Mein Dev-C++ behauptet, er kenne die Typen nicht, die ich in den Headern definiert habe.</p>
<p>Ich weiß leider nicht, wo der fehler liegt, deshalb ein längerer Code:</p>
<pre><code class="language-cpp">//main.cpp

#include &quot;main_h.hpp&quot;
#include &lt;iostream&gt;

using namespace std;

int main() {
  Byte b=64; //test;
};

/////////////////////////////////////
//main_h.hpp

#ifndef MAIN_H
#define MAIN_H

#include &lt;SDL/SDL.h&gt;
#include &quot;ship_h.hpp&quot;
#include &quot;space_h.hpp&quot;

typedef unsigned char Byte;

struct Pos {
  int x,y;
};

struct Size {
  Byte w,h;
};

#endif

/////////////////////////////////////
//sprite.cpp

#include &quot;sprite_h.hpp&quot;

void Sprite::setPos(Pos pos) {
  this-&gt;pos = pos;
};

/////////////////////////////////////
//sprite_h.hpp

#ifndef SPRITE_H
#define SPRITE_H

#include &lt;SDL/SDL.h&gt;
#include &quot;main_h.hpp&quot;

class Sprite {
  public:
    void setPos(Pos pos);
    void show();    
  private:
    Pos pos;
    SDL_Surface* bild;
};

#endif

/////////////////////////////////////
//animsprite.cpp

#include &quot;animsprite_h.hpp&quot;

Animsprite::setAnim(Byte index) {
  bild = bilder[index];
};

/////////////////////////////////////
//animsprite_h.hpp

#ifndef ANIMSPRITE_H
#define ANIMSPRITE_H

#include &quot;sprite_h.hpp&quot;
#include &lt;SDL/SDL.h&gt;

class Animsprite : public Sprite {
  public:
    void setAnim(Byte index);
  private: 
    Byte anzAnim;
    SDL_Surface** bilder;
};

#endif

/////////////////////////////////////
//ship.cpp

#include &quot;ship_h.hpp&quot;

Ship::Ship(SDL_Surface** bilder,Byte anzAnim,Byte leben,Byte speedX,Byte speedY) {
  bilder = new SDL_Surface*[anzAnim];
  this-&gt;anzAnim = anzAnim;
  this-&gt;leben = leben;
  this-&gt;dx = speedX;
  this-&gt;dy = speedY;
};

Ship::~Ship() {
  delete[] bilder;
};

void Ship::show() {
  //noch nichts
};

void Ship::move() {
  //noch nichts
};

/////////////////////////////////////
//ship_h.hpp

#ifndef SHIP_H
#define SHIP_H

#include &lt;SDL/SDL.h&gt;
#include &quot;main_h.hpp&quot;
#include &quot;animsprite_h.hpp&quot;

class Ship : public Animsprite {
  public:
    Ship(SDL_Surface* bild,Byte leben,Byte speedX,Byte speedY);
    ~Ship();
    void move();
  private:
    Byte dx,dy;
    Byte leben;
};

#endif
</code></pre>
<p>Compiler schrieb:</p>
<blockquote>
<p>9 sprite_h.hpp: variable or field <code>setPos' declared void 9 sprite_h.hpp: expected</code>;' before '(' token<br />
12 sprite_h.hpp: `Pos' does not name a type</p>
<p>9 animsprite_h.hpp: variable or field <code>setAnim' declared void 9 animsprite_h.hpp: expected</code>;' before '(' token<br />
11 animsprite_h.hpp: `Byte' does not name a type</p>
<p>10 ship_h.hpp: <code>Byte' has not been declared 10 ship_h.hpp: ISO C++ forbids declaration of</code>leben' with no type<br />
10 ship_h.hpp: ISO C++ forbids declaration of <code>speedX' with no type 10 ship_h.hpp: ISO C++ forbids declaration of</code>speedY' with no type</p>
<p>15 ship_h.hpp: `Byte' does not name a type //Doch!!! <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=":confused:"
      alt="😕"
    /></p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/topic/174673/problem-mit-headern</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 21:52:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/174673.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 01 Mar 2007 19:56:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Headern on Thu, 01 Mar 2007 19:56:10 GMT]]></title><description><![CDATA[<p>Mein Dev-C++ behauptet, er kenne die Typen nicht, die ich in den Headern definiert habe.</p>
<p>Ich weiß leider nicht, wo der fehler liegt, deshalb ein längerer Code:</p>
<pre><code class="language-cpp">//main.cpp

#include &quot;main_h.hpp&quot;
#include &lt;iostream&gt;

using namespace std;

int main() {
  Byte b=64; //test;
};

/////////////////////////////////////
//main_h.hpp

#ifndef MAIN_H
#define MAIN_H

#include &lt;SDL/SDL.h&gt;
#include &quot;ship_h.hpp&quot;
#include &quot;space_h.hpp&quot;

typedef unsigned char Byte;

struct Pos {
  int x,y;
};

struct Size {
  Byte w,h;
};

#endif

/////////////////////////////////////
//sprite.cpp

#include &quot;sprite_h.hpp&quot;

void Sprite::setPos(Pos pos) {
  this-&gt;pos = pos;
};

/////////////////////////////////////
//sprite_h.hpp

#ifndef SPRITE_H
#define SPRITE_H

#include &lt;SDL/SDL.h&gt;
#include &quot;main_h.hpp&quot;

class Sprite {
  public:
    void setPos(Pos pos);
    void show();    
  private:
    Pos pos;
    SDL_Surface* bild;
};

#endif

/////////////////////////////////////
//animsprite.cpp

#include &quot;animsprite_h.hpp&quot;

Animsprite::setAnim(Byte index) {
  bild = bilder[index];
};

/////////////////////////////////////
//animsprite_h.hpp

#ifndef ANIMSPRITE_H
#define ANIMSPRITE_H

#include &quot;sprite_h.hpp&quot;
#include &lt;SDL/SDL.h&gt;

class Animsprite : public Sprite {
  public:
    void setAnim(Byte index);
  private: 
    Byte anzAnim;
    SDL_Surface** bilder;
};

#endif

/////////////////////////////////////
//ship.cpp

#include &quot;ship_h.hpp&quot;

Ship::Ship(SDL_Surface** bilder,Byte anzAnim,Byte leben,Byte speedX,Byte speedY) {
  bilder = new SDL_Surface*[anzAnim];
  this-&gt;anzAnim = anzAnim;
  this-&gt;leben = leben;
  this-&gt;dx = speedX;
  this-&gt;dy = speedY;
};

Ship::~Ship() {
  delete[] bilder;
};

void Ship::show() {
  //noch nichts
};

void Ship::move() {
  //noch nichts
};

/////////////////////////////////////
//ship_h.hpp

#ifndef SHIP_H
#define SHIP_H

#include &lt;SDL/SDL.h&gt;
#include &quot;main_h.hpp&quot;
#include &quot;animsprite_h.hpp&quot;

class Ship : public Animsprite {
  public:
    Ship(SDL_Surface* bild,Byte leben,Byte speedX,Byte speedY);
    ~Ship();
    void move();
  private:
    Byte dx,dy;
    Byte leben;
};

#endif
</code></pre>
<p>Compiler schrieb:</p>
<blockquote>
<p>9 sprite_h.hpp: variable or field <code>setPos' declared void 9 sprite_h.hpp: expected</code>;' before '(' token<br />
12 sprite_h.hpp: `Pos' does not name a type</p>
<p>9 animsprite_h.hpp: variable or field <code>setAnim' declared void 9 animsprite_h.hpp: expected</code>;' before '(' token<br />
11 animsprite_h.hpp: `Byte' does not name a type</p>
<p>10 ship_h.hpp: <code>Byte' has not been declared 10 ship_h.hpp: ISO C++ forbids declaration of</code>leben' with no type<br />
10 ship_h.hpp: ISO C++ forbids declaration of <code>speedX' with no type 10 ship_h.hpp: ISO C++ forbids declaration of</code>speedY' with no type</p>
<p>15 ship_h.hpp: `Byte' does not name a type //Doch!!! <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=":confused:"
      alt="😕"
    /></p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1237719</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1237719</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Thu, 01 Mar 2007 19:56:10 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Headern on Thu, 01 Mar 2007 20:47:25 GMT]]></title><description><![CDATA[<p>Soll ich die Frage anders formulieren?</p>
<p>Generell:<br />
Brauchen normale .cpp Dateien haben nur ein #include, weil alle anderen in den Header reinkommen,<br />
<em>oder</em><br />
muss ich in jeder Datei alle Header einbinden, von denen ich die Typen/Klassen in gerade dieser Datei brauche?</p>
<p>Der Fehler liegt höchstwarscheinlich bei irgend etwas, was mit einem &quot;#&quot; markiert ist. Das schränkt die Suche doch schon mal ein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1237754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1237754</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Thu, 01 Mar 2007 20:47:25 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Headern on Fri, 02 Mar 2007 07:23:06 GMT]]></title><description><![CDATA[<p>Dein Problem ist, daß sich die Header gegenseitig einbinden - &quot;main_h.hpp&quot; inkludiert &quot;ship_h.hpp&quot; und &quot;space_h.hpp&quot;, diese verwenden wiederum die &quot;main_h.hpp&quot;. Durch die Art, wie der Präprozessor sich durch diese #includes (und die Include-Guards) hangelt, kommt dann womöglich die Reihenfolge der Deklarationen durcheinander, so daß z.B. der Typedef von 'Pos' erst hinter der Sprite-Klasse landet. Diese zyklischen Abhängigkeiten mußt du auf jeden Fall aufbrechen - mitunter reicht es, einige überflüssige #includes aus den Headern in die .CPP Files zu verlagern, im Extremfall helfen nur Forward-Deklarationen.</p>
<p>(PS: Ans Ende einer Funktionsdefinition kommt kein Semikolon)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1237849</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1237849</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 02 Mar 2007 07:23:06 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Headern on Fri, 02 Mar 2007 14:08:13 GMT]]></title><description><![CDATA[<p>Danke, das hat mir schon weitergeholfen.</p>
<p>Ich habe den Verdacht, dass ich in abgeleiteten Klassen keine privaten Attribute der &quot;Mutterklasse&quot; benutzen kann. Was für einen Sichtbarkeitsbereich benutze ich denn dann?</p>
<p>Protectet. Google war schneller. <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>Nochwas: Ich möchte, dass jedes Sprite die Funktion &quot;show&quot; hat, die Implementierung aber von der &quot;Endklasse&quot; abhängt. Der Compiler meckert, dass ship keine show methode hätte, hat es aber, weil es ja auf Umwegen auch ein Sprite ist.<br />
Wie mach ich dem das Klar?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1238091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1238091</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Fri, 02 Mar 2007 14:08:13 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Headern on Fri, 02 Mar 2007 14:24:30 GMT]]></title><description><![CDATA[<p>Deine Objekte sind überhaupt nicht polymorph. Mach mal wenigstens den Sprite-Dtor virtual:</p>
<pre><code class="language-cpp">class Sprite {
  public:
    void setPos(Pos pos);
    void show();    
    virtual ~Sprite()
    {
       // leer
    }
  private:
    Pos pos;
    SDL_Surface* bild;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1238123</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1238123</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Fri, 02 Mar 2007 14:24:30 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Headern on Fri, 02 Mar 2007 14:29:06 GMT]]></title><description><![CDATA[<p>Hmm du zwingst den dazu dir ne Fehlermeldung zu bringe, wenn du eine reinvirtuelle Funktion hast und du sie in der abgeleiteten Klasse nicht implementiert hast. Mit einer virtuellen Funktion kannst du sie überschreiben ..</p>
<pre><code class="language-cpp">class human 
{
public:
    virtual bool run(void) = 0;
    virtual bool sing(void); 
};
</code></pre>
<pre><code class="language-cpp">class child : public human
{
public:
    bool say(const std::string&amp;);    

public:
    // virtual bool run(void) {} // Wenn du &quot;run&quot; rauslässt, bekommst du ne Fehlermeldung ;)
    // Wenn du &quot;sing&quot; rauslässt wird die Funktion der Basisklasse genommen ...
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1238125</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1238125</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Fri, 02 Mar 2007 14:29:06 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Headern on Fri, 02 Mar 2007 14:51:40 GMT]]></title><description><![CDATA[<p>OK <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>
<p>undefined reference to `vtable for sprite´</p>
<p>Was könnte das bedeuten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1238131</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1238131</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Fri, 02 Mar 2007 14:51:40 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Headern on Fri, 02 Mar 2007 17:43:39 GMT]]></title><description><![CDATA[<p>Halleluja!<br />
Alles Klar.<br />
Der Thread kann gelöscht werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1238247</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1238247</guid><dc:creator><![CDATA[obbba]]></dc:creator><pubDate>Fri, 02 Mar 2007 17:43:39 GMT</pubDate></item></channel></rss>