C++ 编译错误:应为‘;)’;在‘之前&’;代币

C++ 编译错误:应为‘;)’;在‘之前&’;代币,c++,pass-by-reference,syntax-error,C++,Pass By Reference,Syntax Error,这是我真的不明白的:我看不到任何事实上会导致这个错误 下面是课程: namespace Engine_Main { class SceneManager { public: SceneManager(Engine& engine); void createScene(); private: Ogre::SceneManager * mSceneMgr; }; } 以及其他一些可供参考的课程: #ifndef ENGINE_H #define ENGINE_

这是我真的不明白的:我看不到任何事实上会导致这个错误

下面是课程:

namespace Engine_Main {

class SceneManager
{
public:
    SceneManager(Engine& engine);
    void createScene();
private:
    Ogre::SceneManager * mSceneMgr;
};


}
以及其他一些可供参考的课程:

#ifndef ENGINE_H
#define ENGINE_H

#include <OGRE/OgreSceneManager.h>
#include <OGRE/OgreRoot.h>
#include "scenemanager.h"
#include "playerinput.h"

namespace Engine_Main {

class Engine
{
public:
    Engine();
    ~Engine();

    void initGameLoop();

    PlayerInput * getPlayerInput();
    PlayerMovement * getPlayerMovement();
    Ogre::Root * getOgreRoot();

private:

    //fields
    PlayerInput * mPInput;
    PlayerMovement * mPMovement;
    Ogre::Root * mRoot;
    //methods
    void registerInput();
    void createScene();
    void renderPosition();
};

}

#endif // ENGINE_H

#include "engine.h"


namespace Engine_Main {

    /**********/
    /* PUBLIC */
    /**********/

    PlayerMovement * Engine::getPlayerMovement() {
        return mPMovement;
    }

    PlayerInput * Engine::getPlayerInput() {
        return mPInput;
    }

    Engine::Engine() {
        mPInput = new PlayerInput();
        mPMovement = new PlayerMovement();
        mRoot = new Ogre::Root("cfg/plugins.cfg", "cfg/engine.cfg", "cfg/engine.log");
    }

    Engine::~Engine(){
        if (mPInput) {
            delete mPInput;
        }

        if (mRoot) {
            delete mRoot;
        }
    }

    void Engine::createScene() {

    }

}
\ifndef发动机
#定义引擎
#包括
#包括
#包括“scenemanager.h”
#包括“playerinput.h”
名称空间引擎{
类引擎
{
公众:
引擎();
~Engine();
void initGameLoop();
PlayerInput*getPlayerInput();
PlayerMovement*获取PlayerMovement();
食人魔::根*getOgreRoot();
私人:
//田地
PlayerInput*mPInput;
PlayerMovement*mPMovement;
食人魔::根*mRoot;
//方法
void registerInput();
void createScene();
void renderPosition();
};
}
#endif//引擎
#包括“发动机.h”
名称空间引擎{
/**********/
/*公开的*/
/**********/
PlayerMovement*引擎::getPlayerMovement(){
回归运动;
}
PlayerInput*引擎::getPlayerInput(){
返回MPI输入;
}
引擎::引擎(){
mPInput=新的PlayerInput();
mPMovement=新播放器移动();
mRoot=newogre::Root(“cfg/plugins.cfg”、“cfg/engine.cfg”、“cfg/engine.log”);
}
引擎::~引擎(){
如果(mPInput){
删除mPInput;
}
如果(mRoot){
删除mRoot;
}
}
void引擎::createScene(){
}
}
我的问题

我做错了什么?

您是否在
“scenemanager.h”
中缺少
引擎的(转发)声明?编译器解析时:

...
SceneManager(Engine&);
...

它需要一个
引擎
类型的声明。您可能需要一个转发声明,如
类引擎在声明
场景管理器
类之前。

您能发布错误和行号吗?这很容易,用给出的信息很难回答这个问题;你还没有告诉我们错误的来龙去脉。什么文件和行号?该文件的文本是什么?只需说
deletempinput等等。它完全满足您的需要。(虽然通常我强烈建议永远不要使用
delete
,而是使用单一的责任包装类,如
unique\u ptr
)这是否回答了您的问题?我试过你说的,但没有用;我只是把
类放在引擎上error:expected unqualified id before'}标记
,这基本上意味着我需要花括号。还有其他建议吗?@Holland您可以在代码中稍后的位置定义一个类,但您需要在某个时间之前使用它。例如,两个不同类之间的循环引用只能使用前向声明<代码>类Foo;类Bar{Foo*ptr;};类Foo{Bar*ptr;}请注意,您只能指向一个正向声明的类。@NiklasR这很有趣,因为虽然以前发生过循环引用,但现在已经没有了,而且我仍然得到了错误。