template vector to vector convert function
I have a base class that has 4 different vectors of parameters: HW,SW,FW,
High level
each class derives from the base class, and needs to be able to convert
from one vector of parameters to another.
Ex: convert(Vector vec1, Vector vec2);
One way of implementing is to use 16 static conversion cases. However,
while there are 4 different types of vectors at the moment, more may be
added at a later time.
not all the classes implements all of the 16 conversions. a lot of them
will use a default conversion (which I want to implement in the base class
returning "no conversion defined error");
class A: public baseClass
Class B: public baseClass
Class C: public baseClass
C::Convert(Vector<HW> vec1, Vector<SW> vec2)
{
vec2[0] = vec1[0] +vec1[1] *1.5;
}
B::Convert(Vector<HW> vec1, Vector<SW> vec2)
{
vec2[0] = vec1[0] +vec1[1] *3.7;
}
A::Convert(Vector<SW> vec1, Vector<HW> vec2)
{
vec2[0] = vec1[2] +vec1[1] *9;
}
What would be a good way of defining a generic conversion? I thought maybe
a template of vectors.
Template<Vector<K>, Vector<T>>
void Convert(const k& vec1, T vec2)
I can't assume that a conversion from each vector to the other exists.
No comments:
Post a Comment