语法错误丢失;前* [英] Syntax error missing ; before *

查看:181
本文介绍了语法错误丢失;前*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个头文件:

  #pragma once 
#includegamestate.h
#includeExitListener.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);
//私有:
ExitListener * mFrameListener;
};

问题是我从VC 8得到以下错误:



InitialGameState.h(16):错误C2143:语法错误:缺少';'before'*'
InitialGameState.h错误C4430:缺少类型说明符 - int。注意:C ++不支持default-int
InitialGameState.h(16):错误C4430:缺少类型说明符 - int。注意:C ++不支持default-int

(它们都引用最后一行)



我有一个类 ExitListener.h 这就是为什么我不会得到错误



编辑:ExitListener.h:



  #pragma once 
#include< Ogre.h>
#include< OIS / OIS.h>
#include< CEGUI / CEGUI.h>
#include< OgreCEGUIRenderer.h>
#includeThing.h
#includeInitialGameState.h

使用命名空间Ogre;
类ExitListener:public OIS :: KeyListener,public OIS :: MouseListener
{
public:
ExitListener(OIS :: Keyboard * keyboard,OIS :: Mouse *鼠标,Camera * cam,std :: vector< Thing *>& vec):
mKeyboard(keyboard),r(0.09),mContinue(true),mRunningAnimation鼠标),mYaw(0),mPitch(0),事物(vec),mCamera(cam),mWDown(false),mSDown(false),mADown(false),
mDDown {
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;
相机* mCamera;
bool mContinue;
bool mRunningAnimation;
std :: vector< Thing *> &东西
bool mWDown;
bool mADown;
bool mDDown;
bool mSDown;
GameState * mOwner;
};

编辑2:



原来,这个问题可以通过向前声明解决,然后直接在我的.cpp文件中包含其他头。



谢谢。 >

解决方案

我的猜测是ExitListener.h包含InitialGameState.h头文件直接或间接。所以在头文件和编译器之间有一个循环依赖,无法找到ExitListener的声明。如果你只需要在这个类中存储ExitListener的指针,那么就不需要包含ExitListener.h头文件。您可以使用 class ExitListener;



EDIT 可以使用上面建议的forward声明,或者从ExitListener.h中删除InitialGameState.h include。您只需要包括GameState.h(基类头文件)。但我更喜欢使用头文件中的前向声明,并且仅在cpp中包含头文件。


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.

解决方案

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.

这篇关于语法错误丢失;前*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆