1

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.

Natalo77
  • 155
  • 7
  • I sure would like to see answers to this specific question. The reported previous answer isn’t exactly the same, and the answers aren’t quite clear, ref include statements. – zipzit Apr 19 '19 at 10:23
  • "*avoiding including unneeded header*" you need to include that header because this file is using declarations from that header. Duplicating required declarations from that header by hand is not a good idea. – user7860670 Apr 19 '19 at 10:37
  • Well, no? I only need to use pointers/references in the header file so I should be able to forward declare these classes in the header, then include the defining header files in the source code file. – Natalo77 Apr 19 '19 at 10:41

0 Answers0