D
Daniel Pitts
I have a Vector (as in math vector) template class.
template <typename component_t>
class Vector { /*...*/ };
It defines what you might expect for operators: =, [] +, -, * (as a
scalar multiply), /, etc...
I have some type which the result of (x*x) is not the same type as x.
OtherType operator*(const SomeType &, const SomeType &).
I would like to be able to define a generic operator* for Vector such
that the following works:
const Vector<OtherType> n = Vector<SomeType>() * SomeType();
I tried
template<typename component_in_t,
typename component_out_t, typename scalar_t>
Vector<component_out_t> operator *(const Vector<component_in_t> &in,
scalar_t scalar) {
Vector<component_out_t> result;
for (int i = 0; i < dimensions; ++i) {
result = in*scalar;
}
return result;
}
But my compiler can't infer component_out_t.
Is there any way to do this?
Thanks,
Daniel.
template <typename component_t>
class Vector { /*...*/ };
It defines what you might expect for operators: =, [] +, -, * (as a
scalar multiply), /, etc...
I have some type which the result of (x*x) is not the same type as x.
OtherType operator*(const SomeType &, const SomeType &).
I would like to be able to define a generic operator* for Vector such
that the following works:
const Vector<OtherType> n = Vector<SomeType>() * SomeType();
I tried
template<typename component_in_t,
typename component_out_t, typename scalar_t>
Vector<component_out_t> operator *(const Vector<component_in_t> &in,
scalar_t scalar) {
Vector<component_out_t> result;
for (int i = 0; i < dimensions; ++i) {
result = in*scalar;
}
return result;
}
But my compiler can't infer component_out_t.
Is there any way to do this?
Thanks,
Daniel.