S
Steven T. Hatton
The comperable operator*() to that shown here works for a non-template
class:
template <typename T>
inline Vector3<T> operator*(const Vector3<T>& v, const T& n)
{
Vector3<T> t(v);
return t *= n;
}
For example let Vector3f be a vector of float values. This works fine:
inline Vector3f operator*(const Vector3f& v, const float& n)
{
Vector3f t(v);
return t *= n;
}
It also works when I overload the template form of the operator*=(). For
example this works for the same template class where the first function
shown above fails:
template <typename T>
inline Vector3<T>& Vector3<T>:perator*=(const T& n)
{
_v[0] *= n;
_v[1] *= n;
_v[2] *= n;
return *this;
}
If I replace the T& n with double& n in the first function, it works.
The error I get when using the first form above is this:
error: no match for 'operator*' in 'v3t0 * 5'
Where I have defined:
Vector3<T> v3t0;
Why?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
class:
template <typename T>
inline Vector3<T> operator*(const Vector3<T>& v, const T& n)
{
Vector3<T> t(v);
return t *= n;
}
For example let Vector3f be a vector of float values. This works fine:
inline Vector3f operator*(const Vector3f& v, const float& n)
{
Vector3f t(v);
return t *= n;
}
It also works when I overload the template form of the operator*=(). For
example this works for the same template class where the first function
shown above fails:
template <typename T>
inline Vector3<T>& Vector3<T>:perator*=(const T& n)
{
_v[0] *= n;
_v[1] *= n;
_v[2] *= n;
return *this;
}
If I replace the T& n with double& n in the first function, it works.
The error I get when using the first form above is this:
error: no match for 'operator*' in 'v3t0 * 5'
Where I have defined:
Vector3<T> v3t0;
Why?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell