instance

unwanted object property changed when changing another object property c#

人走茶凉 提交于 2019-12-31 04:58:07
问题 from what i understand in other posts i know that my objects use same place in memory but how to separate these objects? i tried to use new but it didn't work or i didn't used it correctly. Note that i didnt paste setter and getter here. class Supermarket { List<Product> _products = new List<Product>{ }; List<Customer> _customers = new List<Customer>{ }; } class Customer { List<Product> _purchased= new List<Product>{ }; } class Product { string _id; string _name; DateTime _expireDate; int

I cannot access Position of the cursor (move mouse programatically)

这一生的挚爱 提交于 2019-12-31 04:13:14
问题 this is my code: private void MoveCursor(int x, int y) { // Set the Current cursor, move the cursor's Position, // and set its clipping rectangle to the form. System.Windows.Forms.Cursor cursorMouse = new System.Windows.Forms.Cursor(System.Windows.Forms.Cursor.Current.Handle); cursorMouse.Position = new System.Drawing.Point(x, y); System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(cursorMouse.Position, cursorMouse.Size); } This is what my console says: Error 11 Member 'System

Python: how to refer to an instance name?

只谈情不闲聊 提交于 2019-12-31 01:52:09
问题 I'm collecting instances using the following code: class Hand(): instances = [] def __init__(self): Hand.instances.append(self) self.value = 5 def do_something(self, a): self.value = self.value * a class Foo(): def __init__(self): pass def insty(self): self.hand1 = Hand() self.hand2 = Hand() foo = Foo() foo.insty() print Hand.instances for hand in Hand.instances: print "how do I print the instance name?" The last line is just a way to learn how to to access the instance name so i can call the

Declaring instance variables in iOS - Objective-C

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 11:48:10
问题 Ok, I've read a lot around these days about this topic and I alwyas get confused because the answers is different every search I make. I need to know the best way to declare instance variables in iOS. So far I know I should only declare them inside .m file and leave .h clean. But I can't do it: the compiler gives me compilation erros. Here is some code from .m only. @interface UIDesign () // .m file { NSString *test2 = @"test2"; } @property (nonatomic, assign) int privateInt; @end

Change class instance inside an instance method

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-30 08:35:22
问题 Any idea if there is a way to make the following code to work class Test(object): def __init__(self, var): self.var = var def changeme(self): self = Test(3) t = Test(1) assert t.var == 1 t.changeme() assert t.var == 3 is something like the following safe to use for more complex objects (like django models, to hot swap the db entry the instance is referring to) class Test(object): def __init__(self, var): self.var = var def changeme(self): new_instance = Test(3) self.__dict__ = new_instance._

Global var vs Shared Instance swift

≡放荡痞女 提交于 2019-12-30 08:17:31
问题 What is the difference between global variable and shared instance in Swift? what are their respective field of use? Could anyone clarify their concept based upon Swift. 回答1: A global variable is a variable that is declared at the top level in a file. So if we had a class called Bar , you could store a reference to an instance of Bar in a global variable like this: var bar = Bar() You would then be able to access the instance from anywhere, like this: bar bar.foo() A shared instance, or

Example of Class with User Input [closed]

陌路散爱 提交于 2019-12-30 07:48:20
问题 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 4 years ago . In most of the examples I have seen online while (trying to) learn classes, the instances of the classes are defined by the programmer. Are there any ways of creating an instance of a class where it the variable that stores the class is defined by the user? This is an example of an object from

Members vs method arguments access in C++

[亡魂溺海] 提交于 2019-12-30 07:08:57
问题 Can I have a method which takes arguments that are denoted with the same names as the members of the holding class? I tried to use this: class Foo { public: int x, y; void set_values(int x, int y) { x = x; y = y; }; }; ... but it doesn't seem to work. Is there any way of accessing the the instance the namespace of which I'm working in, similar to JavaScript's this or Python's self ? 回答1: It's generally a good idea to avoid this kind of confusion by using a naming convention for member

Android Service multiple instances

雨燕双飞 提交于 2019-12-30 07:02:15
问题 Im still a bit new to the Android Service Class. I know you need to start the service from your application with startService(intent), however my problem is my service has methods inside it. I need to start the service with an intent and then create an object of that class in my Activity so I can call methods of the service. The problem is when I do this I create one instance of the service when I start it with an intent and another instance of the service when I create an object of the class

In Java, why can't a super-class method access protected or private methods/variables from a sub-class instance?

核能气质少年 提交于 2019-12-30 06:27:09
问题 Let's start with another behavior: even if you declare a method/variable as private, another instance of the same class can access it. That's OK I can live with it. I call these class-private and not instance-private. Now the question part: For example, at runtime I want to be able to check that all String variables in this class are not null, and if they are null they should be changed to the string "NULL". I can run through the variables using reflection and get their values. But if I