Chromebender
Programmer
First, I scanned this forum for info on this problem, and while I am now aware of a known issue with VC++ and template functions with template parameters that do not appear as function arguments, this does not appear to be the same bug (if it is, please explain how to fix it). AFAIK, programs with that bug will compile and run but only use the first instantiation of a function, which isn't my problem.
Briefly, I have a CVector class that looks like this:
template <typename Type, int length> class CVector
{
public:
void Normalize()
{
int nIndex;
Type norm=Norm();
for (nIndex=0;nIndex<m_ArrayLength;nIndex++)
m_TypeArray[0] /= norm;
};
...
now if I compile my program with this header file "linear.h"
everything works fine. But I don't want to put the implementation in the header file, I want it in a .CPP file.
However, when I remove the function body of Normalize() from the class definition and place it in "linear.cpp" like so:
template <typename Type, int length> void CVector<Type,length>::Normalize()
{
int nIndex;
Type norm =Norm();
for (nIndex=0;nIndex<m_ArrayLength;nIndex++)
m_TypeArray[0] /= norm;
}
VC++ gives me the error:
error LNK2001: unresolved external symbol "public: void __thiscall CVector<double,3>::Normalize(void)" (?Normalize@?$CVector@N$02@@QAEXXZ)
I tried including dummy parameters
Normalize(Type *dummy=0, int dummy2=0) but while it compiles, it gives the same linker error. What kills me is the method works fine as long as I include ALL the code in the class definition in the header file.
Anyone?
Briefly, I have a CVector class that looks like this:
template <typename Type, int length> class CVector
{
public:
void Normalize()
{
int nIndex;
Type norm=Norm();
for (nIndex=0;nIndex<m_ArrayLength;nIndex++)
m_TypeArray[0] /= norm;
};
...
now if I compile my program with this header file "linear.h"
everything works fine. But I don't want to put the implementation in the header file, I want it in a .CPP file.
However, when I remove the function body of Normalize() from the class definition and place it in "linear.cpp" like so:
template <typename Type, int length> void CVector<Type,length>::Normalize()
{
int nIndex;
Type norm =Norm();
for (nIndex=0;nIndex<m_ArrayLength;nIndex++)
m_TypeArray[0] /= norm;
}
VC++ gives me the error:
error LNK2001: unresolved external symbol "public: void __thiscall CVector<double,3>::Normalize(void)" (?Normalize@?$CVector@N$02@@QAEXXZ)
I tried including dummy parameters
Normalize(Type *dummy=0, int dummy2=0) but while it compiles, it gives the same linker error. What kills me is the method works fine as long as I include ALL the code in the class definition in the header file.
Anyone?