编译错误:在'&'标记之前预期')'

zeb*_*und 1 c++ syntax-error pass-by-reference

这是我真的不明白的事情:我没有看到任何真正使这个错误发生的事情.

这是班级:

namespace Engine_Main {

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


}
Run Code Online (Sandbox Code Playgroud)

除了一些其他类以供参考:

#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() {

    }

}
Run Code Online (Sandbox Code Playgroud)

我的问题

我做错了什么?

D.S*_*ley 9

是否缺少的(向前)申报Engine"scenemanager.h"?当编译器解析时:

...
SceneManager(Engine&);
...
Run Code Online (Sandbox Code Playgroud)

它需要一个Engine类型的声明.您可能需要在声明类class Engine;之前的前向声明SceneManager.