IonelBurtan
Programmer
I haven't used template classes for quite a while and now, when I am tring to use it I get a linker problem.
I made a template class
template <class T> class CSearchAlgorithms
{
public:
CSearchAlgorithms(T* pArray, int nCount, T nLookedFor);
virtual ~CSearchAlgorithms();
void LinearSearch();
void BinarySearch();
private:
T* m_pArray;
int m_nCount;
T m_nLookedFor;
};
and place it in SearchAlgorithms.h
the body of the template class is placed in SearchAlgorithms.cpp with funtion declaration like this
like this
template <class T>
void CSearchAlgorithms<T>::LinearSearch()
{
...
}
Then I try to use the template class from the main program. I include SearchAlgorithms.h, and I instantiate with
...
CSearchAlgorithms<int> sa(nArray, nArraySize, nLookedFor);
sa.LinearSearch();
sa.BinarySearch();
...
All compiles well but the linker gives me 4 errors (i have 4 methods in the template class) like this:
SearchProj.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CSearchAlgorithms<int>::~CSearchAlgorithms<int>(void)" (??1?$CSearchAlgorithms@H@@UAE@XZ)
SearchProj.obj : error LNK2001: unresolved external symbol "public: void __thiscall CSearchAlgorithms<int>::BinarySearch(void)" (?BinarySearch@?$CSearchAlgorithms@H@@QAEXXZ)
SearchProj.obj : error LNK2001: unresolved external symbol "public: void __thiscall CSearchAlgorithms<int>::LinearSearch(void)" (?LinearSearch@?$CSearchAlgorithms@H@@QAEXXZ)
SearchProj.obj : error LNK2001: unresolved external symbol "public: __thiscall CSearchAlgorithms<int>::CSearchAlgorithms<int>(int *,int,int)" (??0?$CSearchAlgorithms@H@@QAE@PAHHH@Z)
Debug/SearchProj.exe : fatal error LNK1120: 4 unresolved externals
I am sure I am missig something but i do not remember what
Tnx,
s-)
Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
I made a template class
template <class T> class CSearchAlgorithms
{
public:
CSearchAlgorithms(T* pArray, int nCount, T nLookedFor);
virtual ~CSearchAlgorithms();
void LinearSearch();
void BinarySearch();
private:
T* m_pArray;
int m_nCount;
T m_nLookedFor;
};
and place it in SearchAlgorithms.h
the body of the template class is placed in SearchAlgorithms.cpp with funtion declaration like this
like this
template <class T>
void CSearchAlgorithms<T>::LinearSearch()
{
...
}
Then I try to use the template class from the main program. I include SearchAlgorithms.h, and I instantiate with
...
CSearchAlgorithms<int> sa(nArray, nArraySize, nLookedFor);
sa.LinearSearch();
sa.BinarySearch();
...
All compiles well but the linker gives me 4 errors (i have 4 methods in the template class) like this:
SearchProj.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CSearchAlgorithms<int>::~CSearchAlgorithms<int>(void)" (??1?$CSearchAlgorithms@H@@UAE@XZ)
SearchProj.obj : error LNK2001: unresolved external symbol "public: void __thiscall CSearchAlgorithms<int>::BinarySearch(void)" (?BinarySearch@?$CSearchAlgorithms@H@@QAEXXZ)
SearchProj.obj : error LNK2001: unresolved external symbol "public: void __thiscall CSearchAlgorithms<int>::LinearSearch(void)" (?LinearSearch@?$CSearchAlgorithms@H@@QAEXXZ)
SearchProj.obj : error LNK2001: unresolved external symbol "public: __thiscall CSearchAlgorithms<int>::CSearchAlgorithms<int>(int *,int,int)" (??0?$CSearchAlgorithms@H@@QAE@PAHHH@Z)
Debug/SearchProj.exe : fatal error LNK1120: 4 unresolved externals
I am sure I am missig something but i do not remember what
Tnx,
s-)
Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...