Hello,
Well, maybe it is because of the language barriere on my side but being
very pedantic indeed, your description is not accurate.

Are you familiar with the concept of giving parametes (variables like your _var1 with underscore) to a function (a function within a class is called a method)? Those parameters are always only valid within the function (or in our case within the constructor). This is true whether the constructor's parameter is on the left or the right of the assignment -
other than said in your 1st paragraph - because when there's no assignment at all, the parameters are still known within the function.
The expression "the constructor's variable" you use I find not clear - it is either the parameter for the constructor (aka _var1) or the variable of the class (var1).
The point is, _var1 is un-persistent because it is a parameter.
Its value doesn't belong to the class yet.
To make it part of the class you have to push it into the class variable - you use the assignment to do so, which has the
receiving element on its left side (that's changing):
SomeClass(float _var1, float _var2){
var1 = _var1;
var2 = _var2;
}
Thus the initial values of the parameters _var1 etc. become persistent in the class as var1.
We want that!BTW
you wouldn't write this:
- class SomeClass(float var1 float var2){
-
SomeClass(float _var1, float _var2){
-
var1 = _var1;
-
var2 = _var2;
-
}
- }
but better
- class SomeClass {
- float var1;
- float var2;
-
SomeClass(float _var1, float _var2){
-
var1 = _var1;
-
var2 = _var2;
-
}
-
}
Then you write:
SomeClass(float _var1, float _var2){
_var1 = var1;
_var2 = var2;
variables would be persistent, and next time I called for
SomeClass.whatev(); the local variables would be remembered and could be
iterated/manipulated/called or whatever was needed?
Nope, not at all! Wrong.
To have the parameter on the left side doesn't make any sense I am afraid. Right solution see above (_var1 must be right of the sign = ; test it).
You might want to look at this again:
// Even though there are multiple objects, we still only need one class.
// No matter how many cookies we make, only one cookie cutter is needed.
class Car {
color c;
float xpos;
float ypos;
float xspeed;
// The Constructor is defined with arguments.
Car(color tempC, float tempXpos, float tempYpos, float tempXspeed) {
c = tempC;
xpos = tempXpos;
ypos = tempYpos;
xspeed = tempXspeed;
}
This is from
http://www.processing.org/learning/objectsSorry to bother you with this stuff but I think with some of your assumptions, your code might not work as expected.
Please ask again when you like.
Greetings, Chrisir
