Hi, All!
I'm coding array template class.
Header file is
template <class T, int N>
class CMyArray
{
public:
CMyArray(int _len=0);
~CMyArray();
protected:
int nSize;
int m_nMaxSize;
T * data;
}
and cpp file is
#include "MyArray.h"
template <class T, int N>
CMyArray<T, N>::CMyArray(int _len)
: nSize(0)
, m_nMaxSize(_len)
, data(_len > 0 ? new T[_len] : NULL)
{
if(m_nMaxSize > 0)
memset(data, 0x00, m_nMaxSize * sizeof(T));
}
and calling code is
#include "MyArray.h"
typedef CMyArray<USHORT, 256> ArrayUShort;
ArrayUShort arrIDs;
...
then while compile, link error.
but, writing at header file without cpp file's implement,
template <class T, int N>
class CMyArray
{
public:
CMyArray(int _len=0)
: nSize(0)
, m_nMaxSize(_len)
, data(_len > 0 ? new T[_len] : NULL)
{
if(m_nMaxSize > 0)
memset(data, 0x00, m_nMaxSize * sizeof(T));
}
~CMyArray();
protected:
int nSize;
int m_nMaxSize;
T * data;
}
above code has no problem.
but I want to implement in cpp file.