I can pass in a Child to a member function expecting a Parent, however when using vectors I get a compile error saying there\'s no matching declaration. See the CorrelationEngin
This is not possible in C++, this requires a feature called covariance.
Even if type A
is a subclass of type B
, type X
is completely unrelated to type X
Thus you cannot pass std::vector
to a function expecting std::vector
, since they are unrelated types. Even pass by reference/pointer will not work.
There are two ways to get around this.
One would be to make both vectors hold pointers to Event
, then they would have identical types.
The other, would be to make the function a template function, as Daniel suggests.
You would need to fix the signature as well, as billz points out.