Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Syntax error: identifier 'x' when 2 headers include each other

Syntax error: identifier 'x' when 2 headers include each other

Scheduled Pinned Locked Moved C / C++ / MFC
csharphelpvisual-studio
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Ylis
    wrote on last edited by
    #1

    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

    J T 2 Replies Last reply
    0
    • Y Ylis

      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

      J Offline
      J Offline
      Jens Doose
      wrote on last edited by
      #2

      Instead 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

      1 Reply Last reply
      0
      • Y Ylis

        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

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        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;
        };
        #endif

        SDLgraphics.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

        Y 1 Reply Last reply
        0
        • T toxcct

          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;
          };
          #endif

          SDLgraphics.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

          Y Offline
          Y Offline
          Ylis
          wrote on last edited by
          #4

          thx :-D

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups