Is the practice or some other design of malicious software true for implementing a constructor for a derived class receiving an object of a base class? I need this in the following vector / matrix structure. I want to define the code for matrix / vector multiplication only once - in the Matrix class (in the * operator). But in the Matrix class, I can only return the abstract type of the base class:
template<class Value_T, unsigned int N>
class VectorT
{
...
};
class Vector4 : public VectorT<double, 4>
{
public:
...
Vector4(const VectorT<double, 4>& base);
...
};
VectorT<value_type, N> operator*(const VectorT<value_type, N>& v) const
{
VectorT<value_type, N> vRes;
...
return vRes;
}
Vector4 v;
Matrix4 m;
VectorT<double, 4> vMult = m * v;
Vector4 vMult = m * v;
My main goal is to reuse the matrix / vector multiplication code and therefore define it in the matrix class for all possible specifications of the template matrix classes Matrix and Vector.
source
share