有一个家长班和一个班级. n个子班数.但是一次只有一个子类才可以访问我的父类.如何实现此目的? [英] There is one Parent class & n number of child classes. But at a time only one child class only should access my parent class.. How to achieve this?

查看:89
本文介绍了有一个家长班和一个班级. n个子班数.但是一次只有一个子类才可以访问我的父类.如何实现此目的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我正在设计一个游戏应用程序(赛车).那里有n个用户.在比赛路径上,隧道在那里.在该隧道内,只有一个用户可以进入该隧道.只有该用户退出后,其他用户才能进入该用户.

如何为此/

Eg I''m designing one gaming application(Car Race). In that there are n number of users. In the race path, tunnel is there. Inside that tunnel, only one user can enter into it. After that user comes out only, another user can enter into it.

How to design a class for this/

推荐答案

OK设计类,因此从汽车派生出隧道的过程将受阻.相反,每辆车到达隧道时,都需要先检查是否有另一辆车在其中.隧道的实例将返回true,直到其中的汽车离开为止,直到它离开为止,您的代码才会让新车进入隧道.这意味着您要排队等候进入隧道的汽车.
OK, so it would be retarded for a tunnel to be derived from a car. Instead, each car, when it gets to the tunnel, needs to check first if another car is in it. The instance of tunnel will return true until the car in there leaves, and until it does, your code won''t let the new car enter the tunnel. which means you''d have a queue of some sort, of cars waiting to enter the tunnel.


我不明白您的父类所描述的内容.虽然...如果您对隧道有疑虑-也许最好关闭隧道门? :)(例如:愚蠢但最简单的方法是拥有一个BOOL变量,该变量仅在隧道为空时才会获得TRUE值):)
I can''t understand what your parent class describes. Although... if you are warring about the tunnel - maybe it''ll be better to close the tunnel gate? :) (for example: the stupid, but most simple way is to have a BOOL variable which will get TRUE value only when the tunnel is empty) :)


不可能.每个子类都是父类的实例.访问与它无关,它是父类.您必须手动创建某种阻止机制,或者从整体上重新考虑您的设计.最好的选择是编辑您的帖子,并告诉我们为什么要这么做.
Impossible. Every child class IS an instance of the parent class. Accessing has nothing to do with it, it IS the parent class. You''d have to create some sort of blocking mechanism, by hand, or rethink your design as a whole. Your best bet would be to edit your post and tell us why you want to do this.


这篇关于有一个家长班和一个班级. n个子班数.但是一次只有一个子类才可以访问我的父类.如何实现此目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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