G
giganut
Hi,
I'm using MS VS.Net2003, and I'm getting a linker error in a project for a
templated friend function
Specifically:
template <class T> class Vec3
{...
friend Vec3<T> operator -( const Vec3<T>& v );
};
Then later I have defined:
template <class T> inline Vec3<T> operator -(const Vec3<T>& v)
{
return Vec3<T>( -v.n[0], -v.n[1], -v.n[2] );
}
and explicitly instantiated:
typedef Vec3<double> Vec3d;
But, then I get a linker error:
error LNK2019: unresolved external symbol "class Vec3<double> __cdecl
operator-(class Vec3<double> const &)" (??G@YA?AV?$Vec3@N@@ABV0@@Z)
referenced in function "bool __cdecl pointToTriDist(class Vec3<double>,class
Vec3<double> *,double,double &,class Vec3<double> &,class Vec3<double> &,int
*)" (?pointToTriDist@@YA_NV?$Vec3@N@@PAV1@NAANAAV1@3PAH@Z)
This happens for all the templated friend functions (global) defined in the
template classes. What is the cause for this ? How can I fix this ?
Thanks,
-g
I'm using MS VS.Net2003, and I'm getting a linker error in a project for a
templated friend function
Specifically:
template <class T> class Vec3
{...
friend Vec3<T> operator -( const Vec3<T>& v );
};
Then later I have defined:
template <class T> inline Vec3<T> operator -(const Vec3<T>& v)
{
return Vec3<T>( -v.n[0], -v.n[1], -v.n[2] );
}
and explicitly instantiated:
typedef Vec3<double> Vec3d;
But, then I get a linker error:
error LNK2019: unresolved external symbol "class Vec3<double> __cdecl
operator-(class Vec3<double> const &)" (??G@YA?AV?$Vec3@N@@ABV0@@Z)
referenced in function "bool __cdecl pointToTriDist(class Vec3<double>,class
Vec3<double> *,double,double &,class Vec3<double> &,class Vec3<double> &,int
*)" (?pointToTriDist@@YA_NV?$Vec3@N@@PAV1@NAANAAV1@3PAH@Z)
This happens for all the templated friend functions (global) defined in the
template classes. What is the cause for this ? How can I fix this ?
Thanks,
-g