I joined a research project in which the OOQP library is used. It uses an abstract class
OoqpVector (inherited by several subclasses) and a number of methods, such as:
virtual double dotProductWith(OoqpVector& v) = 0
This method is implemented by subclasses
DistributedVector. Because of genericity,
OoqpVector::dotProductWith allows all possible combinations:
However in practice, the method is called on vectors of the same type only (combinations 1 and 2). Therefore, the authors implemented
DistributedVector::dotProductWith(OoqpVector&) by dynamically casting the parameter to the current type.
Although this works, I find it a bit ugly and wonder if we can implement the same behavior without casts.
An option would be to get rid of
OoqpVector::dotProductWith, declare the specialized methods
DistributedVector::dotProductWith(DistributedVector&), and force the calling methods to impose the two vector types to be equal. However, our code uses a bunch of OoqpVectors everywhere and is relatively generic, so this might be difficult to achieve.
Do you see a way to fix that?
Source: Windows Questions C++