How do you forward declare classes that exist within a namespace?

41 Views Asked by At

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

#pragma once

#ifndef _CAMCONTROL_H_
#define _CAMCONTROL_H_

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

class CameraController
{
public:
    CameraController();
    ~CameraController();
    CameraController(Ogre::SceneManager& scnMgrRef);

private:
    Ogre::SceneNode* camNode;

    Ogre::SceneManager* scnMgr;
};

#endif

This is the cpp file

#include "CameraController.h"

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



CameraController::CameraController()
{
     scnMgr = nullptr;
     camNode = nullptr;
}


CameraController::~CameraController()
{
    delete camNode;
}

CameraController::CameraController(Ogre::SceneManager & scnMgrRef) 
{
    scnMgr = &scnMgrRef;
}

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

EDIT

I attempted the redefinition as marked in the duplicate:

#pragma once


#ifndef _CAMCONTROL_H_
#define _CAMCONTROL_H_

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




class Ogre3DApplication;


const int INITIAL_CAM_X = 3000;
const int INITIAL_CAM_Y = 3000;
const int INITIAL_CAM_Z = 3000;


class CameraController
{
public:
    CameraController();
    ~CameraController();
    CameraController(Ogre::SceneManager& scnMgrRef, Ogre3DApplication& parent);

private:
    Ogre::Real getAspectRatio();



private:
    Ogre::SceneNode* camNode;

    Ogre::Camera* camera;

    Ogre::Viewport* viewPort;

    Ogre::SceneManager* scnMgr;
};

#endif

The compiler still throws errors.

Most interestingly, one: Viewport is not a member of Ogre.

0

There are 0 best solutions below