【问题】

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.

 

From: https://stackoverflow.com/questions/1542623/syntax-error-missing-before

最新文章

  1. HTML学习笔记——标签
  2. AndroidのUI体验之ImmersiveMode沉浸模式
  3. php 无限循环
  4. c#代码画图
  5. PL/SQL学习(六)触发器
  6. java生产者消费者问题代码分析
  7. JMS理解2
  8. HDU 5889 (最短路+网络流)
  9. 部分转载[C#性能优化实践]
  10. [线程]Thead 中传参数RuntimeError: thread.__init__() not called
  11. Windows下查看游戏服务器的IP地址
  12. String转换为Map
  13. 5、Python文件类型
  14. 有趣的console.log(console.log输出彩色字,图片等)
  15. [转]How to Create an Add-in for Microsoft Outlook
  16. Python shell对比
  17. MFC中Carray的使用
  18. .net中session的使用
  19. linux的yum报错
  20. 内核抢占实现(preempt) 【转】

热门文章

  1. centos上安装elasticsearch 5.5.1 遇到的各种坑
  2. Revit Family API 添加几何实体
  3. android操作sqlite数据库及心得
  4. GDI+用PNG图片做半透明异型窗口
  5. Java知识回顾 (1) 编译环境与基本变量类型
  6. 排名前16的Java工具类
  7. DELPHI新的变量的声明方法
  8. UITableView分割线样式与颜色
  9. 创建、修改、删除ORACLE表空间
  10. cocos2d-x 3.0 正式版 项目创建