[英]how to manage multiple files, global variables, and defines
我有两个课,“实体”课和“瓷砖”课。
类“实体”具有一些成员函数,这些成员函数使用类型为“ tile”的全局数组。 它还使用一些定义的数字。
类“ tile”包含一个成员变量,该成员变量是指向“ entity”类型的指针。
我想将这些类分为多个.h文件。 我将尝试对其进行重组,但我确实想知道是否有可能这样做。
因此,再次为清楚起见:
“实体”使用类型为“平铺”的全局二维数组
“平铺”用途
有什么方法可以将其分成三个.h文件(每个类一个,所有全局变量和定义一个)。
谢谢!
我不明白为什么您需要三个.h文件。 只需为每个类创建一个单元,然后将全局变量放入Entity的模块中(我不会说您可以避免使用全局变量)。
实体
class Entity
{
<...>
};
实体.cpp
#include "Entity.h"
#include "Tile.h"
Tile array[100];//here's your array
平铺
#include "Entity.h"
class Tile
{
<...>
Entity * ptr;//here's your pointer
};
我认为您只需要对Entity类进行前向声明?
tile.h:
class Entity;
class Tile {
Entity *entity;
...
}
实体.h:
//#include "tile.h" - add this back if you need to refer to tile in Entity defn
class Entity {
...
}
实体.cpp
#include "entity.h"
// Remove the following or put in proper include protection if you uncomment the
// include above
#include "tile.h"
Tile gbl[10][10];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.