C++Cycling包括(三个类,两个虚拟类)
C++ Cycling includes (Three classes, two virtual)
我不知道如何在我的项目中声明一些类,其中包括循环。
(映射->对象->对象管理器->映射->…)
我对三个类都没有发现(有用的),并对两个类尝试了一些可能性(许多形式的正向声明),但没有成功。。。
这是我的类设计(简化形式):
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;
相关文章:
- 如何在C++中从两个单独的for循环中添加两个数组
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- 如何返回一个类的两个对象相加的结果
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 两个字符串在 c++ 中不相等
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 两个文件使用彼此的功能-如何解决
- 如何拥有两个名称相同但返回类型不同的纯虚拟方法
- 从两个不同类继承的非虚拟基类的访问成员
- 无法调用通过两个类继承的虚拟方法
- 两个派生类(十六进制 二进制)的虚拟功能
- 具有相同纯虚拟功能的两个基类
- 在c++中选择两个纯虚拟函数中的一个
- 两个 C++ 可执行对象之间的实时数据通信,一个是 Windows 和另一个在虚拟机 Ubuntu 中
- C++Cycling包括(三个类,两个虚拟类)
- 两次声明纯虚拟函数(在层次结构中的两个类中)是否完全合法
- 在两个项目之间链接时,获取虚拟函数的链接错误
- 将两个目录合并到一个虚拟目录中用于编译/别名包含目录