Making a template - Symbol(s) not found
Posted: Tue Jul 14, 2009 11:48 am
Im trying to create my own Array class, just as the book I read did but Im having a weird problem
Header file:
Im having some trouble with the constructor, here's the implementation:
And finally this is what Xcode(Mac) tells me:
Ive figured out two ways to solve this, but they're not ideal, so if someone could explain whats happening and what needs fixing that'd be great.
My first solution is to include the Array.cpp instead of .h .
The other solution is to move the function implementation to the header file.
Thanks in advance
Sanshin
Edit:
This actually applies to all of the functions.
Header file:
Code: Select all
#ifndef __ARRAY_H__
#define __ARRAY_H__
typedef unsigned short USHORT;
const USHORT DefaultSize = 10;
template <class T>
class saArray
{
public:
saArray(USHORT size = DefaultSize);
saArray(const saArray &rhs);
~saArray(){delete [] pType;}
saArray& operator=(const saArray&);
T& operator[](USHORT offset);
const T& operator[](USHORT offset) const {return pType[offset];}
USHORT GetSize(){return Size;}
private:
T *pType;
USHORT Size;
};
#endif
Code: Select all
template <class T>
saArray<T>::saArray(USHORT size):
Size(size)
{
pType = new T[size];
for(USHORT i = 0; i<size; i++)
pType[i] = 0;
}
Code: Select all
"saArray<unsigned short>::saArray(unsigned short)", referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
My first solution is to include the Array.cpp instead of .h .
The other solution is to move the function implementation to the header file.
Thanks in advance
Sanshin
Edit:
This actually applies to all of the functions.