请指点一些帮助 [英] Some help with Pointers please

查看:59
本文介绍了请指点一些帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我在使用此功能时遇到了一些问题:


Hello,

I am having some trouble with this function:


展开 | 选择 | Wrap | 行号

推荐答案


您好,


我遇到一些麻烦功能:

Hello,

I am having some trouble with this function:


展开 | 选择 | Wrap | 行号



您可以从文件中发布更多代码吗?你加入两个房间是什么意思?
Can you post more code from your file. What do you mean by joining two rooms??



我有一个叫做房间的课程我有10个房间(room1 room2 ....... room10)房间通过指针(北,南,东,西)连接。我有一个创建所有房间的功能,上面的代码是连接房间的功能部分(room1 North通往room2,room2 South指向room1)。


我想要实现的是2路连接(North指向room2,南指向room1)


以下是整个功能,我评论了我在尝试什么实现。如果您需要更多代码请告诉我。


提前致谢:)

I have a class called "room" I have 10 rooms (room1 room2.......room10) the rooms are connected via pointers (North, South, East,West). I have a function that creates all the rooms, and the code above is a section from the function that connects the rooms (room1 North leads to room2 and room2 South points to room1).

What I''m trying to achieve is a 2 way connection (North points to room2 and south points to room1)

Below is the entire function, ive commented what I''m trying to achieve. If you need more code let me know.

Thanks in advance :)

展开 | 选择 | 换行 | 行号


我会在每个if ... else分支中添加一些代码,它在x中调用addConnection(我认为是room2) - 你必须使用相反方向的字符串和this指针。 br />

你可能遇到的是一个无限循环 - 你设置room1'的连接,然后调用room2'的连接,然后调用room1的连接等。为了解决这个问题,我会的在设置连接之前检查当前房间的北/南/东/西指针是否为NULL - 如果它是NULL,你没问题,但是如果它不是NULL,那么它'' s已经设置好了,不应该改变。
I would add some code in each if...else branch that calls addConnection in x (which I presume is room2) - you''ll have to use the opposite direction string and the this pointer.

Something you might run into is an infinite loop here - you set room1''s connection, then call room2''s connection, which in turn calls room1''s connection, etc. etc. In order to fix this, I''d check to see if the current room''s north/south/east/west pointer is NULL before setting the connection - if it''s NULL, you''re OK, but if it''s not NULL, it''s already been set and shouldn''t be changed.


这篇关于请指点一些帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆