【问题】

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. [原创]Linux下网络性能测试Netperf工具介绍及安装

    [原创]Linux下网络性能测试Netperf工具介绍及安装 1 官方网站 http://www.netperf.org/netperf/ 2 Netperf介绍 Netperf是一种网络性能的测试工 ...

  2. nginx File not found 错误(转)

    当我没初始配在lnmp的时候,用浏览器打开查看php能否解析网页的时出现File not found 不用惊奇让我我们分析一下 使用php-fpm解析PHP,"No input file s ...

  3. Revit API遍历全部风管,找到与风管相关的墙开洞

    涉及向量计算,求相交等相关技术. )                 {                     foreach (Face face in solid.Faces)          ...

  4. Visual Studio 2015 update 2 setup fails with "missing or damaged package kb3022398"

    Question     Hi, I wanted to install Visual Studio Professional 2015 Update 2 from my MSDN abo (web ...

  5. 在Visual Studio中使用层关系图描述系统架构、技术栈

    当需要描述项目的架构或技术栈的时候,可以考虑使用层关系图. 在解决方案下添加一个名称为"TailspinToys.DesignModel"的建模项目. 在新建的建模项目下添加一个名 ...

  6. SQL Server 2008 安装教程

    http://www.downcc.com/tech/4135.html 序列号:Developer: PTTFM-X467G-P7RH2-3Q6CG-4DMYB

  7. .NET:System.Security.Cryptography.CryptographicException 的解决办法

    详细内容参考此网址:http://social.msdn.microsoft.com/Forums/en-US/ec93922a-fd1e-4225-b5cf-1472ebb3acd1/systems ...

  8. spring websocket自动断开连接再创建引发的问题解决方案

    问题:由于 web session 超时时间为 30 分钟,如用户在 web session 规定时间内没有退出系统,但由于其它原因 用户却断开的 websocket 的连接,如果用户还要聊天或是其它 ...

  9. SPClaimsUtility.AuthenticateFormsUser 方法的一个小问题

    前言 最近,开启了Form认证,发现Form账号前面加空格,或者后面加空格都可以登录站点,但是提示未共享. 解决方法 后来bing了很多帖子,发现大家都遇到过类似的问题,问题是由于SPClaimsUt ...

  10. mysql error You must reset your password using ALTER USER statement before executing this statement.

    mysql修改密码Your password does not satisfy the current policy requirements 出现这个问题的原因是:密码过于简单.刚安装的mysql的 ...