Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error missing ; before *

Tags:

c++

visual-c++

I have a header file like so:

#pragma once
#include "gamestate.h"
#include "ExitListener.h"

class InitialGameState : public GameState
{
public:
  InitialGameState(Ogre::Camera *cam, Ogre::SceneManager *sceneMgr, OIS::Keyboard      *keyboard, OIS::Mouse *mouse, Ogre::Root *root);
  ~InitialGameState(void);
  virtual bool update(Ogre::Real time);
  virtual void pause(void);
  virtual void start(void);
  void keyPressed(const OIS::KeyEvent &e);
  void keyReleased(const OIS::KeyEvent &e);
//private:
ExitListener *mFrameListener;
};

The problem with this is that I get the following errors from VC 8:

InitialGameState.h(16) : error C2143: syntax error : missing ';' before '*'  
InitialGameState.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int  
InitialGameState.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int  

(they all refer to the last line)

I have a class ExitListener.h which is why I don't get the errors

Edit: ExitListener.h:

#pragma once
#include <Ogre.h>
#include <OIS/OIS.h>
#include <CEGUI/CEGUI.h>
#include <OgreCEGUIRenderer.h>
#include "Thing.h"
#include "InitialGameState.h"

using namespace Ogre;
class ExitListener : public FrameListener, public OIS::KeyListener, public     OIS::MouseListener
{
public:
ExitListener(OIS::Keyboard *keyboard, OIS::Mouse *mouse, Camera *cam, std::vector<Thing*> &vec): 
  mKeyboard(keyboard), r(0.09), mContinue(true), mRunningAnimation(false),
mMouse(mouse), mYaw(0), mPitch(0), things(vec), mCamera(cam), mWDown(false), mSDown(false), mADown(false),
mDDown(false)
{
  things = vec;
  mKeyboard->setEventCallback(this);
  mMouse->setEventCallback(this);
}
bool frameStarted(const FrameEvent& evt);   
bool keyPressed(const OIS::KeyEvent &e);
bool keyReleased(const OIS::KeyEvent &e);
bool mouseMoved(const OIS::MouseEvent &e);
bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id);

void setOwner(GameState *g);

private:
  AnimationState *mSwim;
  Radian r;
  Radian mYaw;
  Radian mPitch;
  OIS::Keyboard *mKeyboard;
  OIS::Mouse *mMouse;
  Camera *mCamera;
  bool mContinue;
  bool mRunningAnimation;
  std::vector<Thing*> &things;
  bool mWDown;
  bool mADown;
  bool mDDown;
  bool mSDown;
  GameState *mOwner;
};

Edit 2:

It turned out that the problem could be solved by a forward declaration and then including the other header directly in my .cpp file.

Thanks.

like image 785
tomjen Avatar asked Oct 09 '09 08:10

tomjen


5 Answers

My guess is that ExitListener.h is including InitialGameState.h header file either directly or indirectly. So there is a circular dependency between the header file and compiler is unable to find the declaration for ExitListener. If you just need to store the pointer of ExitListener in this class then there is no need to include the ExitListener.h header file. Instead you can just use the forward declaration as class ExitListener;

EDIT: You can use the forward declaration as suggested above, or remove the InitialGameState.h include from ExitListener.h . You need to include GameState.h (the base class header file) only. But I prefer to use the forward declarations in header file and include the header file only in cpp.

like image 135
Naveen Avatar answered Oct 21 '22 18:10

Naveen


  1. The errors don't refer to the last line, but to the line before the last line. (Please be precise. If people know the compiler well which emits this error message, their guesses might be a lot better if they know the exact line it is given for.)
  2. "ExitListener.h" is not a class, but a header. (This isn't Java.) One would assume that there is a class ExitListener defined (or at least declared) inside that header, but there could just as well be some other class, none at all, or many classes.
  3. Without this header, it's impossible to say exactly what's wrong, although either circular dependencies between these two headers or a missing ; at the end of the ExitListener class' definition is a very good guess that fits my experience with such errors. At the very least I'm sure the error means that the compiler doesn't know what ExitListener is.
  4. As others have said, you do not need a class definition in order to declare a pointer to that class, so (assuming that "ExitListener.h" defines the ExitListener class) you don't need to include the header at all. A simple forward declaration class ExitListener; is sufficient enough to declare the ExitListener *mFrameListener member. (You will need to include the full class definition in order to implement the InitialGameState member functions that deal with ExitListener, though. If you implement these functions in the header where InitialGameState is defined, you will need to keep that "ExitListener.h" include.)
like image 37
sbi Avatar answered Oct 21 '22 16:10

sbi


Apparently the problem is with ExitListener definition, it's not considered valid at that point.

like image 24
Ashalynd Avatar answered Oct 21 '22 17:10

Ashalynd


The error is in the ExitListener.h file (or any of the file it includes). Often this problem is due to a missing ; at the end of the class.

If you add the code of this file I will be able to help you further.

like image 25
Patrice Bernassola Avatar answered Oct 21 '22 18:10

Patrice Bernassola


The problem ExitListener was incorrectly declared. This is the only solution for VS to say this. Check that there was no error when compiling the ExitListener class. (and that you did not forget the trailing ";")

A side note Here you are using a pointer to ExitListener. You do not need to know the size or internal layout of ExitListener if you just declare a pointer. A forward declaration would be enough.

like image 21
NewbiZ Avatar answered Oct 21 '22 18:10

NewbiZ