G
Guest
I want to create a Matrix class of a type using Generics.
class Matrix<T> { ... }
I want to provide an Add method that will add the the 2 Matrices under the
type of int. My add method would look like:
public static Matrix<T> operator +(Matrix<T> a, Matrix<T> b) {
// check for same size
Matrix<T> c = new Matrix<T>(a.Row, a.Col);
for(int i=0;i<a.Row;i++)
for(int j=0;j<a.Col;j++)
c[i,j] = a[i,j]+b[i,j];
return c;
}
For a matrix of Matrix(int) I want to add the elements of type int. There
is a problem with operators and Types.
Is there a way around this?
Thanks,
Marc
class Matrix<T> { ... }
I want to provide an Add method that will add the the 2 Matrices under the
type of int. My add method would look like:
public static Matrix<T> operator +(Matrix<T> a, Matrix<T> b) {
// check for same size
Matrix<T> c = new Matrix<T>(a.Row, a.Col);
for(int i=0;i<a.Row;i++)
for(int j=0;j<a.Col;j++)
c[i,j] = a[i,j]+b[i,j];
return c;
}
For a matrix of Matrix(int) I want to add the elements of type int. There
is a problem with operators and Types.
Is there a way around this?
Thanks,
Marc