-1

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

Natalo77
  • 155
  • 7
  • Please post a [mcve] not bit of files that we can't use to compile ourselves. Trim out all the unnecessary declarations and definitions. – Richard Critten Apr 19 '19 at 13:37
  • @RichardCritten done. sorry about that – Natalo77 Apr 19 '19 at 13:45
  • Once the question has an answer you should not change the topic or change the code reflecting the answer. You should ask a new question. This one is done. Remember the main purpose of a `StackOverflow` question is to help future readers with the same problem. With all of this said the original problem likely should have been closed as a typo. – drescherjm Apr 19 '19 at 14:39

1 Answers1

1

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

tarkmeper
  • 767
  • 3
  • 12
  • Oh jesus christ. Let me fix that real quick, there are more problems! – Natalo77 Apr 19 '19 at 13:40
  • I can't remember for sure off the top of my head, but I believe the declaration of Ogre::Real won't work as a non-pointer declaration. Since the class is only forward declared it can't create a concrete variable. – tarkmeper Apr 19 '19 at 13:45
  • As if that tiny error throws such a myriad of compiler issues within visual studio. Thank you so much! – Natalo77 Apr 19 '19 at 13:52