class

Is it possible to initialise two classes, that require pointers to each other, at the same time?

荒凉一梦 提交于 2021-02-08 06:52:19
问题 I am making a snake game. I have two classes, snake and food . When I call snake->move() it needs to check that there are no collisions and for this purpose it needs to know what food 's position is and therefore requires a pointer to food . food has a function that moves it to a new random position, move->setNewPosition() , which needs to know the position of snake so that it doesn't collide with the snake when it moves. For this purpose, it requires a pointer to snake . Therefore, for both

Is it possible to initialise two classes, that require pointers to each other, at the same time?

霸气de小男生 提交于 2021-02-08 06:50:13
问题 I am making a snake game. I have two classes, snake and food . When I call snake->move() it needs to check that there are no collisions and for this purpose it needs to know what food 's position is and therefore requires a pointer to food . food has a function that moves it to a new random position, move->setNewPosition() , which needs to know the position of snake so that it doesn't collide with the snake when it moves. For this purpose, it requires a pointer to snake . Therefore, for both

Using random_device in classes [closed]

亡梦爱人 提交于 2021-02-08 06:11:18
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 7 years ago . Improve this question What part of this code would be logical to call in your main{} class, and what part should be used within (for instance) the constructor of a new object (what should I pass as argument(s)), and why? The question is more along the lines of, what is the best way of passing

Using random_device in classes [closed]

孤街浪徒 提交于 2021-02-08 06:10:09
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 7 years ago . Improve this question What part of this code would be logical to call in your main{} class, and what part should be used within (for instance) the constructor of a new object (what should I pass as argument(s)), and why? The question is more along the lines of, what is the best way of passing

Using a class module variable in a userform (Error '424' object required)

血红的双手。 提交于 2021-02-08 05:58:40
问题 I have a class module which hosts a worksheet_change sub, and in that sub a Userform has to pop up. I want to use a number of variables from the class module in the Userform's code. Whatever I do, however, I can't get it to work. I have tried to apply the method from this very lenghty guide, but to no avail. Other threads on SO weren't able to help me. Private cell As Range Public WithEvents m_wb As Workbook Property Get cellr() As Range Set cellr = cell End Property Property Set cellr

How to add methods to manipulate an array of class objects?

こ雲淡風輕ζ 提交于 2021-02-08 04:41:09
问题 I didnt know how to word the question, so sorry if it doesnt really make sense, but it should start making sense here. Also, I am sorry if the solution is really, really simple. Google couldnt understand what I was asking (probs cause I was asking it wrong :P) So I wrote a class that I called OrderSelection In my program I need to have an array of OrderSelection objects, and I need to perform actions on this array (re-ordering, sorting etc). What I am doing right now is keeping methods in the

How to add methods to manipulate an array of class objects?

淺唱寂寞╮ 提交于 2021-02-08 04:41:05
问题 I didnt know how to word the question, so sorry if it doesnt really make sense, but it should start making sense here. Also, I am sorry if the solution is really, really simple. Google couldnt understand what I was asking (probs cause I was asking it wrong :P) So I wrote a class that I called OrderSelection In my program I need to have an array of OrderSelection objects, and I need to perform actions on this array (re-ordering, sorting etc). What I am doing right now is keeping methods in the

global dictionary within a class python

試著忘記壹切 提交于 2021-02-08 02:42:48
问题 I'm designing an inventory class in Python, it is supposed to keep track of the items a store has in stock, add new ones, and delete them, as well. The trouble comes from my "item" definitions within the class. When I add another item to my dictionary, it replaces it, it doesn't add it. I appreciate your help! Why won't it add??? class Store: def __init__(self, name, email): self.name = name self.email = email # two accessor methods def getName(self): return self.name def getEmail(self):

global dictionary within a class python

ⅰ亾dé卋堺 提交于 2021-02-08 02:41:39
问题 I'm designing an inventory class in Python, it is supposed to keep track of the items a store has in stock, add new ones, and delete them, as well. The trouble comes from my "item" definitions within the class. When I add another item to my dictionary, it replaces it, it doesn't add it. I appreciate your help! Why won't it add??? class Store: def __init__(self, name, email): self.name = name self.email = email # two accessor methods def getName(self): return self.name def getEmail(self):

Change type of an object after its creation (typecasting in Python)

…衆ロ難τιáo~ 提交于 2021-02-08 02:11:14
问题 In my project, I generate an object obj of type CubicObject . At runtime, a GUI setting should be allowed to change the type of obj to Tofu or Box (and back), depending on what the user wants to do and what (s)he thinks the object is best represented by. Then the user should benefit from specific algorithms implemented in the corresponding classes. I am looking for a nice implementation of this behaviour. I have played with the code below, which changes the __class__ attribute, but I am sure