c++ - Compiler error C2653: not a class or namespace name -


so have been having extremely frustrating problem lately visual c++ 2012. until few hours ago, writing code fine , working intended, until decided optimize things , deleted few classes. fixed of errors popping because of that, e.g. false includes, etc. unfortunately, after vs compiler went crazy. started giving me errors such as:

error 14 error c2653: 'class' : not class or namespace name 

or even

error 5 error c2143: syntax error : missing ';' before '}' error 4 error c2059: syntax error : '>' 

i've checked multiple times, , in it's right place: headers included, symbols placed should be.

as far understand, problem not code compiler itself... visual studio can annoying @ times, guess. anyway, grateful if me out on one.

(by way, disabling precompiled headers did not work)

relevant parts of code:

error 14:

#include "playerentity.h" playerentity::playerentity(void) {} // line causes error 

error 5:

class gamescreen : public basescreen { public:     ... private:     ... }; // line causes error 

error 4:

private:      std::vector<baseentity*> _entitylist; // line causes error 

whole playerentity.h file:

#ifndef pentity_h #define pentity_h  #include "baseentity.h"  class playerentity : public baseentity { public:     playerentity(void);     playerentity(float, float);     virtual ~playerentity(void);      void render(sf::renderwindow&);     void update(); private:     void init(); };  #endif 

whole gamescreen.h file:

#ifndef gscreen_h #define gscreen_h  #include "basescreen.h" #include "baseentity.h" #include "playerentity.h"  class gamescreen : public basescreen { public:     gamescreen(sf::vector2u&);     virtual ~gamescreen(void);      void start();     void stop();      void render(sf::renderwindow&);     void update(void);      void addentity(baseentity*);     void destoryentity(int id); private:     std::vector<baseentity*> _entitylist;     sf::vector2u _screendimensions; };  #endif 

whole baseentity.h file:

#ifndef bsentity_h #define bsentity_h  #include "input.h" #include <sfml/graphics.hpp>  class baseentity { public:     baseentity(void);     virtual ~baseentity(void);      sf::vector2f position;      virtual void update(void);     virtual void render(sf::renderwindow&);     void compare(baseentity*); protected:     sf::texture *_entitytexture;     sf::sprite  _entitysprite;      bool _isalive;     int  _id;       virtual void init(); };  #endif 

whole input.h file:

#ifndef input_h #define input_h  #include "screensystem.h" #include <sfml/window.hpp>  class input { public:     input(void);     input(sf::renderwindow*);     virtual ~input(void);      static bool keypressed(int);     static bool keyreleased(int);      static bool mouseheld(int);     static bool mousereleased(int); private:     static sf::renderwindow *_window; };  #endif 

whole screensystem.h file:

#ifndef ghandler_h #define ghandler_h  #include "basescreen.h" #include "menuscreen.h" #include "gamescreen.h" #include <sfml/window.hpp>  class screensystem { public:     screensystem(void);     screensystem(sf::renderwindow*);     virtual ~screensystem(void);      basescreen *getcurrentscreen(void);     void setscreen(int); private:     int _currentscreenid;      std::vector<basescreen*> _screens;     sf::renderwindow *_window; };  #endif 

you have circular dependency in headers. baseentity.h includes input.h, includes screensystem.h, includes gamescreen.h, in turn re-includes baseentity.h. leads class names appearing before declared, causing compilation failure.

to avoid this, not include headers unnecessarily. example, not include input.h baseentity.h, since it's not needed @ all; , not include basescreen.h screensystem.h since declaration class basescreen; needed, not complete class definition.

also, check not have duplicate header guards. of them not match header name (e.g. ghandler_h screensystem.h), makes me think may have been accidentally copied other headers. finally, don't use reserved names _entitysprite own symbols; simplicity, avoid leading or double underscores.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -