目前设计的lifegame,有creature 和god两个类,creature包含一个生物具有的必须属性和方法,god包含整个世界的属性和若干creature。
但是这里就遇到了一个经典的问题:creature类的一些方法需要访问god的世界属性(获取生存环境的信息),另一方面,god也包含着creature,这样两个类有着相互依赖的关系,在实现上十分为难编译器【编译器不哭QAQ】
这里C++的解决方案是使用前置声明,但是具体使用的姿势也感觉好难,我曾经查过不少blog,发现里面很多办法只是能通过编译,并不能访问对方对象的方法和属性(比如god.creature[1].eat()和creature[1].getLifeNum()这样),也曾打算换语言去实现,不过最终还是找到了正确的姿势:
http://blog.csdn.net/xiqingnian/article/details/41214539
感谢这篇博文的博主。
也可能是短时间内,我还没有在手上的C++两本工具书上找到相关内容介绍,这类语法和规定的细则,感觉还是看工具书靠谱,现在总算解决这个问题了,【吃饭】
(0)LifeGame
最新推荐文章于 2021-05-21 07:30:36 发布