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

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

本文关键字:虚拟 两个 三个 C++Cycling 包括      更新时间:2023-10-16

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

(映射->对象->对象管理器->映射->…)

我对三个类都没有发现(有用的),并对两个类尝试了一些可能性(许多形式的正向声明),但没有成功。。。

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

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(及其子级)正在使用.cpp中的Objects,Object.h的子级正在使用Object_Manager.h中的Map*映射(如果这很重要的话)。

使用这段代码,我得到了许多编译器错误。编译器也不喜欢我的其他解决方案,那么这怎么可能工作呢?

重要:.h中必须保留哪些内容,.cpp文件中必须保留什么内容?儿童班最终需要什么?

谢谢!

删除包含。。。

#include "Object_Manager.h"

从"Object.h"并使用正向声明。。。

class Object_Manager;

同样,删除包含。。。

#include "Map.h"

从"Object_Manager.h",并改用正向声明。。。

class Map;