Forward declaring class: incomplete type

Hi
I have the following code:

MySceneManager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once

#include "my.hpp"

#include "MyScene.hpp"

class MySceneManager 
{
   private:
      std::vector<std::unique_ptr<MyScene>> m_scenes;
      MyScene* m_ptrActiveSceneRef;

   public:

      MyScene* GetActiveScene();

      MyScene* NewScene(const std::string id);
      MyScene* GetScene(const std::string id);

      bool HasScene(const std::string id);
      bool SwitchScene(const std::string id);

      bool DeleteScene(const std::string id);


};



MyScene.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include "my.hpp"

#include "MyObject.hpp"


class MySceneManager;

class MyScene
{
   private:
      std::vector<std::unique_ptr<MyObject>> objects;

   public:
      const std::string SceneID;
      MySceneManager* SceneManagerRef;

      MyScene(const std::string sceneID)
         : SceneID(sceneID)
      {
         std::cout << "created\n";

      }

      virtual ~MyScene()
      {
         std::cout << "destroyed\n";
      }

      bool LoadNewScene(const std::string id)
      {
         SceneManagerRef->SwitchScene(id);
      }


};


I have 2 classes: MySceneMangaer & MyScene
ยจ
MySceneManager includes MyScene in order to have a vector of scenes
but MyScene also needs to have a reference to its "manager"

so i tried forward declaring the MySceneManager class, which worked fine at first
but when i tried using the "SceneManagerRef" pointer (in the LoadNewScene function) i got an error saying : Invalid use of incomplete type

whats going on ?
how can i fix it?
A forward declaration will only allow you to have pointers and references to the class. You will not be able to access any of its member functions. If you split the MyScene class into header and source file you wouldn't have this problem because you can then include MyScene.hpp and call the MyScene member functions from the source file without problems.
Last edited on
Topic archived. No new replies allowed.