I want to implement Vector
and Matrix
classes in C++, such that Vector
and Matrix
objects are able to be multiplied. There are the following 2 structures that I could think of for their implementations:
Implement the template class
Vector
withT*
type of data, and then define template classMatrix
as an array ofVector
s.Implement the template class
Matrix
withT**
type of data, and then inherit template classVector
as aMatrix
with (number of columns = 1).
The disadvantage of the 1st approach is that, Vector
class doesn't take care of column and row vectors and the vector-vector multiplications would be problematic, and in second approach, the Vector
would be treated as a 2D Matrix with (number of columns =1) or T**
.
What would be the best way to implement these 2 classes? Thanks.