syntax question on array for objects
in
Programming Questions
•
2 years ago
Let's say for simplification, I have this is as my class:
class Pt {
int posX;
int posY;
Pt(int _posX, int _posY) {
posX = _posX;
posY = _posY;
}
}
So in another class, I have created a variable of type Pt[ ], as one of its variables/arguments. I made a function called void render () which draws an ellipse through a for loop. How would I access the value, of a variable/argument (posX), of an object Pt that is within an array? Is this possible?
I know that if it is just one instance, you would access it through: nameVariable.posX
if it's within an array how would you write it? nameVariable.posX[i]? I tried several things but it didn't work?
let's say, for variable Pt[] ptXY;
for (int i = 0; i < ptXY.length; i ++) {
ellipse( [goes here], [goes here], Esize, Esize);
}
thank you.
class Pt {
int posX;
int posY;
Pt(int _posX, int _posY) {
posX = _posX;
posY = _posY;
}
}
So in another class, I have created a variable of type Pt[ ], as one of its variables/arguments. I made a function called void render () which draws an ellipse through a for loop. How would I access the value, of a variable/argument (posX), of an object Pt that is within an array? Is this possible?
I know that if it is just one instance, you would access it through: nameVariable.posX
if it's within an array how would you write it? nameVariable.posX[i]? I tried several things but it didn't work?
let's say, for variable Pt[] ptXY;
for (int i = 0; i < ptXY.length; i ++) {
ellipse( [goes here], [goes here], Esize, Esize);
}
thank you.
1