Z
Zerex71
Group,
I'm wondering about the following: Say I have a class called Matrix
which is essentially an array of three numbers, and I call the data
member:
private double array[3];
to be used for general math matrix operations. However, I am going to
create a Vector class which subclasses from Matrix, since a vector is
a matrix. In it, I would like to access three data members:
private double x;
private double y;
private double z;
1. Is there a way to refer to x, y, and z when using Vector instead of
array[0..2]? In other words, when I say Vector.x, it automatically
reads/writes array[0]. Is this possible?
2. Is there a way that I can avoid duplicating data members between
instances of both classes?
3. Or in inheritance, will I just wind up with six doubles, and have
to deal with it?
Thanks,
Mike
I'm wondering about the following: Say I have a class called Matrix
which is essentially an array of three numbers, and I call the data
member:
private double array[3];
to be used for general math matrix operations. However, I am going to
create a Vector class which subclasses from Matrix, since a vector is
a matrix. In it, I would like to access three data members:
private double x;
private double y;
private double z;
1. Is there a way to refer to x, y, and z when using Vector instead of
array[0..2]? In other words, when I say Vector.x, it automatically
reads/writes array[0]. Is this possible?
2. Is there a way that I can avoid duplicating data members between
instances of both classes?
3. Or in inheritance, will I just wind up with six doubles, and have
to deal with it?
Thanks,
Mike