   Templated destructor not working
//ArrayList.hclass ArrayList {public:ArrayList() { size = numElements = 0; }~ArrayList();private:void clear();T* array;int size, numElements;};//ArrayList.cpptemplate <class T>ArrayList::~ArrayList() {clear();}//OtherFile.h#include "ArrayList.hclass X {public:ArrayList<Z> list;}The above code gives me the following errors:error LNK2019: unresolved external symbol "public: __thiscall ArrayList<struct Z>::~ArrayList<struct Z>(void)" (??1?$ArrayList@UZQuestion@@@@QAE@XZ) referenced in function "public: virtual __thiscall CFlashCardsDlg::~CFlashCardsDlg(void)" (??1CFlashCardsDlg@@UAE@XZ)error LNK2001: unresolved external symbol "public: __thiscall ArrayList<struct Z>::~ArrayList<struct Z>(void)" (??1?$ArrayList@UZQuestion@@@@QAE@XZ)
  Try:template <class T>ArrayList<T>::~ArrayList() {clear();};  Nope, same errors.   ;  Templates must be specified entirely in headers. If you don't want to do that, include your .cpp at the end of your header.   ;Quote:Original post by SfpianoNope, same errors.Hm.. Try writing ArrayList<T>::~ArrayList<T> instead then, both versions compile for me in VC6.I assume that the lack of template keyword before the original class is just a typo.edit:Quote:Original post by Anonymous PosterTemplates must be specified entirely in headers. If you don't want to do that, include your .cpp at the end of your header.Doh.. I know I should've read the source (and comments in this case) too.   ;  Ah, didn't know that. Thanks.   ;  Also, you seem to be missing the template declaration for the class declaration itself: template <typename T> class ArrayList.However, if you want this kind of functionality, you should be using std::vector anyway.   ;  Here's why you got those errors:Templated classes don't actually exist after you write them.  If you have a templated class written but never used, it never even gets compiled.  Templates are used during the C++ "pre-processor", meaning that template declarations are kind of like humongous #define MACRO(x) statements.  The MACRO doesn't exist until you use it, and even then it's not really a function.  When you first write this code,ArrayList<int> list;the comiler creates and compiles a new class called ArrayList<int> from everything it has about the class in the current .cpp file.  So unless you include the implementation of the class's functions into every file that uses it, the class's functions never actually get compiled.  Hence you write the whole thing in the header file, or else include the .cpp at the bottom of the header.Make sense?~BenDilts( void );   