Hello,
I created a template matrix class and some appropriate binary operators like:
The first line of each such binary operator is a check, like:
But I was wondering if one could model the mathematical behavior of matrices? By that I mean that (unless you define them) there are no valid operations with matrices of different dimensions.
I think this could be well modeled with types because usually there are no valid operations between different types. And with templates one could define a type "on demand".
So I'm thinking of a syntax like:
would define a 4 by 4 matrix whose elements are floats, and it would be a different type than a
Matrix<float, 3, 3> ...
So is there a way to do this with templates? Or any other way?
Thanks in advance,
Harinezumi
I created a template matrix class and some appropriate binary operators like:
Code:
template <typename ContainedType> Matrix<ContainedType> operator+ (const Matrix<ContainedType>& lhs, const Matrix<ContainedType>& rhs) { ... }
Code:
assert(lhs.rows == rhs.rows && lhs.columns == rhs.columns);
I think this could be well modeled with types because usually there are no valid operations between different types. And with templates one could define a type "on demand".
So I'm thinking of a syntax like:
Code:
Matrix<float, 4, 4> matrix_4x4;
Matrix<float, 3, 3> ...
So is there a way to do this with templates? Or any other way?
Thanks in advance,
Harinezumi
Comment