Accessing other instances of class in method
in
Programming Questions
•
11 months ago
Assuming I have something like the code below, and I'm updating point[10] I'd like to be able to access other instances of point[], eg. point[6]. Can I /should I do this by passing the index of the object to the update() method or should I just move update() out of the class altogether (which seems self-defeating)? What if I need access to an unkown number of instances so can't define the parameters in advance?
TIA for helping me improve my OOP
class MyClass{
float fX, fY;
float update(){
//access other instances here
//eg updating point[10] but need to access point[6] and possibly others!
}
}
MyClass[] point = new MyClass[20];
TIA for helping me improve my OOP

class MyClass{
float fX, fY;
float update(){
//access other instances here
//eg updating point[10] but need to access point[6] and possibly others!
}
}
MyClass[] point = new MyClass[20];
1