Looking to implement a cross-product operator^ oveload for template Vector3D class ideally that overload (though I think highly improbable/impossible) should be able to receive two different parameter types and return a third s.t.
Vector3D<Distance> r;
Vector3D<Force> F;
Vector3D<Moment> M = r^F;
Since I assume that this is impossible and/or improbable I would be open to forcing the return parameter type to double s.t.
Vector3D<Distance> r;
Vector3D<Force> F;
Vector3D<double> M = r^F;
However when I do that in the code below I get the following linking error even though template class Vector3D is instantiated:
1>Source.obj : error LNK2019: unresolved external symbol "public: class
Vector3D<double> const __thiscall Vector3D<double>::operator^<double>(class
Vector3D<double> const &)const " (??$?TN@?$Vector3D@N@@QBE?
Thank you in advance for the help.
//Vector3D.h
template <typename T>
class Vector3D
{
public:
'''
template <typename Arg>
const Vector3D<double> operator^ (const Vector3D<Arg>& p_other) const;
'''
private:
//////////////////////////////////////////////////////////////////////////
// *** PRIVATE DATA MEMBERS ***
//////////////////////////////////////////////////////////////////////////
T m_elem[3];
}
//Vector3D.cpp
/// Calculate the cross product
//
template <typename T>
template <typename Arg>
const Vector3D<double> Vector3D<T>::operator^ (const Vector3D<Arg>& p_right) const
{
// Local variables
Vector3D<T> left(*this);
Vector3D<double> cross_product;
// Calculation
cross_product.m_elem[0] = left.m_elem[1] * p_right.m_elem[2] - left.m_elem[2] * p_right.m_elem[1];
cross_product.m_elem[1] = left.m_elem[2] * p_right.m_elem[0] - left.m_elem[0] * p_right.m_elem[2];
cross_product.m_elem[2] = left.m_elem[0] * p_right.m_elem[1] - left.m_elem[1] * p_right.m_elem[0];
return cross_product;
}
template class Vector3D<double>;