C++ Cycling包括(三个类,两个virtual)

C++ Cycling includes (Three classes, two virtual)

我不知道如何在我的项目中声明一些 类,其中包括循环。

(地图 -> Object -> Object_Manager -> 地图 ->...)

我发现三个 类 什么都没有(有用)并尝试了两个 类 的一些可能性(许多形式的前向声明) - 但没有成功...

这是我为 类(简化形式)设计的:

Map.h

//some other includes
#include "Object.h"

#ifndef Map_H
#define Map_H

class Map{
   public: 
     Map();
     virtual ~Map();
     void move_object(Object* object, int x, int y); 
     // some other functions and members, that should be usable for and with Objects
}


Object.h

#include "Object_Manager.h"

#ifndef Object_H
#define Object_H

class Object { 
   public:  
      Object();     
      virtual ~Object();
      void interact_with(Object* object); 
      //some other stuff

   protected: 
      Object_Manager* object_manager;  
}


Object_Manager.h

#include "Map.h"

class Object_Manager{
   public: 
      Object_Manager(); 
      ~Object_Manager(); 

      Map* map; 

      //some other stuff
}



Map.h(及其 children)在 .cpp 中使用 Object,而 Object.h 的 children 使用来自 Object_Manager.h 的 Map* 地图- 如果这很重要。

使用此代码我得到很多 compiler-ERRORs。 编译器也不喜欢我的其他解决方案,所以这怎么行?

重要提示:什么必须保留在 .h 文件中,什么必须保留在 .cpp 文件中? child-classes 最终需要什么?

谢谢!

删除包含...

#include "Object_Manager.h"

来自 "Object.h" 并改用前向声明...

class Object_Manager;

同样,删除包含...

#include "Map.h"

来自 "Object_Manager.h" 并改用前向声明...

class Map;