本文介绍了在其定义中的类变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个愚蠢的问题。我试图做一个文本泥。我需要每个Room类包含其他房间类,人们可以参考时,试图移动他们或从他们获取信息。但是,我不能这样做,因为我显然不能在其定义中声明一个类。那么,我该怎么做呢?这是我的意思,当我说我不能这样做:
This is probably a dumb question. I am trying to make a text-mud. I need each Room class to contain other Room classes that one can refer to when trying to move to them or get information from them. However, I can not do that because I obviously can not declare a class within its definition. So, how do I do this? Here's what I mean when I state I can not do it:
class Room {
public:
Room NorthRoom;
Room EastRoom;
Room SouthRoom;
Room WestRoom;
};
推荐答案
不可能有 Room
成员变量。
class Room {
public:
Room* NorthRoom;
Room* EastRoom;
Room* SouthRoom;
Room* WestRoom;
};
这篇关于在其定义中的类变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!