c++includeforward-declarationogre

Class redefinition problems using forward declarations


NOTE: Reupload of a question wrongly marked as duplicate

I'm working with Ogre, but my question resides specifically within namespaces.

I haven't been able to find an answer that helps me here.

I'm trying to forward declare Ogre::xyz classes within my header file for a CameraController.

This is the header file

class Ogre;
class Ogre::SceneNode;
class Ogre::SceneManager;

class CameraController
{
private:
    Ogre::SceneNode* camNode;

    Ogre::SceneManager* scnMgr;
};

This is the cpp file

#include "CameraController.h"

#include <OgreSceneManager.h>
#include <OgreSceneNode.h>

... definitions of functions.

What's the correct way to achieve what I'm trying to do here, in avoiding including unneeded header files within the CameraController.h file

ATTEMPT TO FIX

I attempted the redefinition as marked in a 'duplicate' that talked about declaring classes in namespaces:

namespace Ogre
{
    class SceneManager;
    class SceneNode;
    class Camera;
    class Viewport;
    class Real;
}

class CameraController
{
private:
    Ogre::Real getAspectRatio();

private:
    Ogre::SceneNode* camNode;

    Ogre::Camera* camera;

    Ogre::Viewport* viewPort;

    Ogre::SceneManager* scnMgr;
};

EDIT

So the error I am having now is that the classes that I forward declare within the Ogre namespace are being redefined by the headers that I include in the .cpp file


Solution

  • The capitalization of ViewPort and Viewport in the forward declaration is different. C++ would see them as different values.