首页 \ 问答 \ 儿童访问同一父母的其他孩子的元素(Children Accessing Elements of Other Children of the Same Parent)

儿童访问同一父母的其他孩子的元素(Children Accessing Elements of Other Children of the Same Parent)

我目前正在使用C ++开发RPG游戏,我已经到了在地图上包含事件的地步。

我希望能够让地图上的活动治愈玩家。 我认为最简单的方法是使用'this'关键字从游戏中传递指向事件对象的指针。 当我开始这样做时,有一大堆编译器错误似乎是由于试图包含一个当前试图包含另一个类的类而导致的。 (我觉得无限循环?)

例如。 我有我的'游戏'类,它有一个属于'mapManager'类的公共成员。 然后'mapManager'对象将'event'对象作为成员。 “游戏”对象在其成员中也有一个“玩家”对象。 我需要让“玩家”拥有的“事件”对象更改变量。 我可以诚实地在需要时抛出指针,但这可能会变得很麻烦。

我想要问的是,是否有一种简单的方法让父母的孩子访问该父母的另一个孩子,或者是否更容易将指针扔给需要他们指向其他孩子的所有子类。

哇...这没什么意义,但希望有人能够理解得足以给我一个好的答案。 这是一些代码,以防它有所帮助。

:game.h

包括“player.h”包括“event.h”

类比赛{public:player Player; 事件事件; };

:player.h

班主任{public:game * Game;

};

:event.h

课堂活动{public:game * Game; };

刚刚导致“游戏没有命名类型”,所以我试图在event.h和player.h中包含游戏并得到相同的错误。 我想要做的是能够从内部事件访问玩家的变量HP。


I'm currently developing an RPG game using C++ and I got to the point of including events on the map.

I wanted to be able to have the event on the map heal the player. I figured the easiest way to do this was to pass a pointer to the event object from the game using the 'this' keyword. When I got into doing this there were a whole bunch of compiler errors that seem to have resulted from trying to include a class that was currently attempting to include the other class. (endless loop I guess?)

For example. I have my 'game' class and it has a public member belonging to the 'mapManager' class. The 'mapManager' object then has the 'event' object as a member. The 'game' object also has a 'player' object within its' members. I need to have the 'event' object change variables that the 'player' has. I could honestly throw pointers whenever I need them but this might get cumbersome.

What I'm trying to ask is if there is an easy way to have a child of a parent access another child of that parent or if it would just be easier to throw pointers to all of the child classes needing them pointing to the other children.

Wow... that made very little sense but hopefully someone can understand enough to give me a good answer. Here's some code in case it helps.

:game.h

include "player.h" include "event.h"

class game { public: player Player; event Event; };

:player.h

class player { public: game* Game;

};

:event.h

class event { public: game* Game; };

Having just this results in "game does not name a type" and so I tried to include game in event.h and player.h and got the same error. What I want to do is be able to access player's variable HP from inside event.


原文:
更新时间:2022-05-02 13:05

最满意答案

我不知道是否有更好的方法,但我所做的是使用IIS永久重定向:

  1. 转到网站属性的“主目录”选项卡
  2. 选择“重定向到URL”选项
  3. 在“重定向到”文本框中输入“ http:// yournewurl $ S $ Q”
  4. 检查选项“上面输入的确切URL”和“此资源的永久重定向”

因此,对http://youroldurl/path/page?querystring所有请求都会永久重定向到http://yournewurl/path/page?querystring

更多细节可以在这里找到

PS:以上是针对II6的步骤,IIS 7可能有所不同,我无法真正记得。

更新:

在默认页面和404页面中使用404直接与以下内容:

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://yournewurl/"
%> 

I do not know if there is a better method, but what I do is using IIS permanent redirect:

  1. Go to the "Home Directory" tab of the site properties
  2. Select option "A redirection to a URL"
  3. Enter "http://yournewurl$S$Q" in the "Redirect to" text box
  4. Check both the options "The exact URL entered above", and "A permanent redirection for this resource"

So all requests for http://youroldurl/path/page?querystring get permanently redirected to http://yournewurl/path/page?querystring

More details can be found here.

PS: Above are steps for II6, IIS 7 might differ, I can't really recall.

Update:

Using 404 direct with the following in the default page and the 404 page:

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://yournewurl/"
%> 

相关问答

更多
  • 您可以使用Classic ASP中的会话对象来隐藏您的javascript重定向 例如 <% session("usemainsite") = Request("usemainsite") if session("usemainsite") <> 1 then %>