【问题】

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

Syntax error missing ; before *的更多相关文章

  1. c++,函数名不要和某个类名相同 (syntax error : missing ';' before identifier....)

    直接上代码: // outside.h class Outside { private: class Inner { public: Inner(Outside& out) : out_(ou ...

  2. error C2143: syntax error : missing ';' before 'type'

    许久之前,就想看看C和C++,看看这两种神奇的编程语言,但是一直被这样或者那样的琐事给耽搁了(狂喷自己的拖延症). 今天翻开自己的移动硬盘找到一本古老的书籍:<The C Programming ...

  3. VC++中编译C出错:error C2143: syntax error : missing ';' before 'type'

    转摘自:http://preceo.blog.51cto.com/6225017/1130931 近来写程序时发现了一个问题,用 VC 编译 C语言是 总是提示一个错误:error C2143: sy ...

  4. error C2143: syntax error : missing ';' before '}'

    今天弄Tab控件,干了一件非常愚蠢的事,没有去声明头文件.这也是今天要记录的问题,提示如下各种 前面一个符号是错误的.如果初学者遇到,算作一个提示,记得声明新类的.h 头文件 标签空间再进一步.cpp ...

  5. syntax error : missing ';' before identifier

    原文解决方案 #include "string.h" #include "stdafx.h" #include "Chapter 01 MyVersi ...

  6. Python3.x运行Python2.x代码报错 syntax error "Missing parentheses in call to 'print'

    #另外一种错误 SyntaxError: Missing parentheses in call to 'print'. Did you mean print( 查看代码,格式如下: print &q ...

  7. syntax error: missing ';' before identifier 'IWebBrowser'

    遇到这个错误. google的结果是 去掉 WIN32_LEAN_AND_MEAN 宏定义 然而由于项目中使用了很多第三方库, 如果去掉这个宏, 会导致其他项目编译错了. 关于这个宏有什么用, 可以百 ...

  8. C++ 编译发现 error C2146: syntax error : missing ';' before identifier 'm_ctrlserver'

    解决这个问题的根源是重复包含了头文件

  9. Cocos2dx 3.6源代码编译错误:syntax error : missing &#39;)&#39; before &#39;{&#39;

    在编译Cocos2dx 3.6版本号时.发现编译错误: 定位代码行: debugForNormalSprite->drawPoints(positions, 4, 8, Color4F{0.0, ...

随机推荐

  1. embOS实时操作系统 - 任务状态

    A task may be in one of several states at any given time. When a task is created, it is placed into ...

  2. 【Go命令教程】1. 标准命令详解

    Go 语言的 1.5 版本在标准命令方面有了重大变更.这倒不是说它们的用法有多大的变化,而是说它们的底层支持已经大变样了.让我们先来对比一下 $GOROOT/pkg/tool/< 平台相关目录 ...

  3. JAVA GC 图解

    http://www.cnblogs.com/hnrainll/archive/2013/11/06/3410042.html http://www.blogjava.net/ldwblog/arch ...

  4. Delphi取UTC时间秒

    自格林威治标准时间1970年1月1日00:00:00 至现在经过多少秒数时间模块Uses   DateUtils;当前时间:中国是 +8时区,换成UTC 就要减掉8小时showMessage(intt ...

  5. Command /usr/sbin/chown failed with exit code 1?

    问题: 解答: 转自:http://stackoverflow.com/questions/7589771/command-usr-sbin-chown-failed-with-exit-code-1

  6. Xcode工程文件打不开:cannot be opened because the project file cannot be parsed

    svn更新代码后,打开xcode工程文件,会出现  xxx..xcodeproj  cannot be opened because the project file cannot be parsed ...

  7. MYSQL 1093 之You can't specify target table for update in FROM clause解决办法

    You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据. 出现以上错误,是因为想将表自身的字 ...

  8. selector属性介绍

    本文来自:http://blog.csdn.net/brokge/article/details/9713041 简介: 根据不同的选定状态来定义不同的现实效果 分为四大属性: android:sta ...

  9. 用ArrayAdapter来创建Spinner(自定义布局、默认布局、动态内容、静态内容)

             android:dropDownWidth 下拉列表宽度 android:dropDownHorizontalOffset 下拉列表距离左边的距离 android:dropDownV ...

  10. 《Python计算机视觉编程》

    <Python计算机视觉编程> 基本信息 作者: (美)Jan Erik Solem 译者: 朱文涛 袁勇 丛书名: 图灵程序设计丛书 出版社:人民邮电出版社 ISBN:978711535 ...