M
Marc Webel
Hi i have a small(?) problem and i hope you can help me.
i have a basis class "Matrix" that contains a 2d matrix.
you can fill the matrix by a method called "setData(int x,int y)".
two child classes "MatrixTypeA" and "MatrixTypeB´" inherit the matrix
and the filling method. ok.
both childs have different attributes and variables but happen to use
the same matrix type to store the data.
now theres a class "MatrixGenerator" that fills data into the matrix of
both... using a method "fillMatrix()" the problem is:
how can i write a method that accepts "MatrixTypeA" AND "MatrixTypeB"?
both inherit the matrix filling method from "Matrix" thus the filling of
the matrix is always the same(the inherited "setData()" method).
can i somehow write "fillMatrix(Matrix obj)" so it will accept all
classes that are childs of "Matrix"? maybe some sort of cast?
thanks for any insight!
My ideal code should be like this:
MAtrixTypeA a;
MatrixTypeB b;
MatrixGenerator mg;
mg.fillMatrix(a);
mg.fillMatrix(b);
i have a basis class "Matrix" that contains a 2d matrix.
you can fill the matrix by a method called "setData(int x,int y)".
two child classes "MatrixTypeA" and "MatrixTypeB´" inherit the matrix
and the filling method. ok.
both childs have different attributes and variables but happen to use
the same matrix type to store the data.
now theres a class "MatrixGenerator" that fills data into the matrix of
both... using a method "fillMatrix()" the problem is:
how can i write a method that accepts "MatrixTypeA" AND "MatrixTypeB"?
both inherit the matrix filling method from "Matrix" thus the filling of
the matrix is always the same(the inherited "setData()" method).
can i somehow write "fillMatrix(Matrix obj)" so it will accept all
classes that are childs of "Matrix"? maybe some sort of cast?
thanks for any insight!
My ideal code should be like this:
MAtrixTypeA a;
MatrixTypeB b;
MatrixGenerator mg;
mg.fillMatrix(a);
mg.fillMatrix(b);