Syntax error: identifier 'x' when 2 headers include each other
-
I have 2 classes, and both classes needs to know of each other. Here's the headers: sprite.h
#ifndef SPRITE_H #define SPRITE_H #include "SDL.h" #include "SDLgraphics.h" class sprite { public: sprite( char * p_path, int p_noFrames ); void Animate( SDLgraphics &p_g ); SDL_Surface* GetSurface() { return m_image; } SDL_Rect* GetRect() { return &m_image->clip_rect; } protected: float m_x, m_y; int m_noFrames; int m_curFrame; SDL_Surface* m_image; }; #endif
SDLgraphics.h#ifndef SDLgraphics_H #define SDLgraphics_H #include #include #include "SDL.h" #include "sprite.h" class SDLgraphics { public: SDLgraphics(unsigned int p_flags); void Init(int p_width, int p_height); void Draw(sprite *p_sprite, SDL_Rect *p_area); inline void Draw(sprite *p_sprite); void Flip(); protected: SDL_Surface *m_scene; }; #endif
When I try to compile it in Visual Studio 7.0 .NET I get error C2061: syntax error : identifier 'SDLgraphics', and another one relating to sprite. Greatful for any help :-D;P -
I have 2 classes, and both classes needs to know of each other. Here's the headers: sprite.h
#ifndef SPRITE_H #define SPRITE_H #include "SDL.h" #include "SDLgraphics.h" class sprite { public: sprite( char * p_path, int p_noFrames ); void Animate( SDLgraphics &p_g ); SDL_Surface* GetSurface() { return m_image; } SDL_Rect* GetRect() { return &m_image->clip_rect; } protected: float m_x, m_y; int m_noFrames; int m_curFrame; SDL_Surface* m_image; }; #endif
SDLgraphics.h#ifndef SDLgraphics_H #define SDLgraphics_H #include #include #include "SDL.h" #include "sprite.h" class SDLgraphics { public: SDLgraphics(unsigned int p_flags); void Init(int p_width, int p_height); void Draw(sprite *p_sprite, SDL_Rect *p_area); inline void Draw(sprite *p_sprite); void Flip(); protected: SDL_Surface *m_scene; }; #endif
When I try to compile it in Visual Studio 7.0 .NET I get error C2061: syntax error : identifier 'SDLgraphics', and another one relating to sprite. Greatful for any help :-D;Pdeclare one class before defining the other :
sprite.h
#ifndef SPRITE_H
#define SPRITE_H
#include "SDL.h"
#include "SDLgraphics.h"class sprite {
public:
sprite(char * p_path, int p_noFrames);
void Animate(SDLgraphics &p_g);
SDL_Surface* GetSurface() { return m_image; }
SDL_Rect* GetRect() { return &m_image->clip_rect; }
protected:
float m_x, m_y;
int m_noFrames;
int m_curFrame;
SDL_Surface* m_image;
};
#endifSDLgraphics.h
#ifndef SDLgraphics_H
#define SDLgraphics_H
#include <unknown_file1.h> // your post don't precise what file is included#include <unknown_file2.h> // because the "<>" are treated as HTML tags
#include "SDL.h"
#include "sprite.h"class sprite; // Add this line here...
class SDLgraphics {
public:
SDLgraphics(unsigned int p_flags);
void Init(int p_width, int p_height);
void Draw(sprite *p_sprite, SDL_Rect *p_area);
inline void Draw(sprite *p_sprite);
void Flip();
protected:
SDL_Surface *m_scene;
};
#endif
TOXCCT >>> GEII power
-
I have 2 classes, and both classes needs to know of each other. Here's the headers: sprite.h
#ifndef SPRITE_H #define SPRITE_H #include "SDL.h" #include "SDLgraphics.h" class sprite { public: sprite( char * p_path, int p_noFrames ); void Animate( SDLgraphics &p_g ); SDL_Surface* GetSurface() { return m_image; } SDL_Rect* GetRect() { return &m_image->clip_rect; } protected: float m_x, m_y; int m_noFrames; int m_curFrame; SDL_Surface* m_image; }; #endif
SDLgraphics.h#ifndef SDLgraphics_H #define SDLgraphics_H #include #include #include "SDL.h" #include "sprite.h" class SDLgraphics { public: SDLgraphics(unsigned int p_flags); void Init(int p_width, int p_height); void Draw(sprite *p_sprite, SDL_Rect *p_area); inline void Draw(sprite *p_sprite); void Flip(); protected: SDL_Surface *m_scene; }; #endif
When I try to compile it in Visual Studio 7.0 .NET I get error C2061: syntax error : identifier 'SDLgraphics', and another one relating to sprite. Greatful for any help :-D;PInstead of including sprite.h in SDLGraphics.h try a forward declaration: SDLgraphics.h
#ifndef SDLgraphics_H #define SDLgraphics_H #include #include #include "SDL.h" class sprite; class SDLgraphics { public ...
That should work in this case, because in SDLgraphics.h you only need sprite pointers. Jens -
declare one class before defining the other :
sprite.h
#ifndef SPRITE_H
#define SPRITE_H
#include "SDL.h"
#include "SDLgraphics.h"class sprite {
public:
sprite(char * p_path, int p_noFrames);
void Animate(SDLgraphics &p_g);
SDL_Surface* GetSurface() { return m_image; }
SDL_Rect* GetRect() { return &m_image->clip_rect; }
protected:
float m_x, m_y;
int m_noFrames;
int m_curFrame;
SDL_Surface* m_image;
};
#endifSDLgraphics.h
#ifndef SDLgraphics_H
#define SDLgraphics_H
#include <unknown_file1.h> // your post don't precise what file is included#include <unknown_file2.h> // because the "<>" are treated as HTML tags
#include "SDL.h"
#include "sprite.h"class sprite; // Add this line here...
class SDLgraphics {
public:
SDLgraphics(unsigned int p_flags);
void Init(int p_width, int p_height);
void Draw(sprite *p_sprite, SDL_Rect *p_area);
inline void Draw(sprite *p_sprite);
void Flip();
protected:
SDL_Surface *m_scene;
};
#endif
TOXCCT >>> GEII power