X
xz
For example, I have a Class Date with internal variable year, month
and day.
In Java I would write:
class Date{
int year;
int month;
int day;
Date(int year, int month, int day) {
this.year = year;
this.month = month;
this.day;
}
}
That is, simply name every parameter as what it is and use this.*
within the method body to differentiate the class variables and the
parameters.
However, in C++ it seems I cannot do this. In this particular
example, probably I can write:
Date:ate(int y, int m, int d): year(y), month(m), day(d) {
}
However, the letters "y", "m" or "d" are not that informative. Thus I
don't really like this naming style.
Is there a better way to do this?
What would you guys use to replace "y", "m" and "d" in this case?
and day.
In Java I would write:
class Date{
int year;
int month;
int day;
Date(int year, int month, int day) {
this.year = year;
this.month = month;
this.day;
}
}
That is, simply name every parameter as what it is and use this.*
within the method body to differentiate the class variables and the
parameters.
However, in C++ it seems I cannot do this. In this particular
example, probably I can write:
Date:ate(int y, int m, int d): year(y), month(m), day(d) {
}
However, the letters "y", "m" or "d" are not that informative. Thus I
don't really like this naming style.
Is there a better way to do this?
What would you guys use to replace "y", "m" and "d" in this case?