   c++ templates trouble
  I'm currently making a quick class for use as a 2d version of the stl vector class. (i've named it matrix)Header:   #include <vector>template <class T>class Matrix {public:Matrix(); //default ctorMatrix(int xDimension, int yDimension); //config ctor~Matrix(); //dtorvoid in(int x, int y, T data); //store in matrixT out(int x, int y);  //retrieve value from matrixprivate:std::vector<T> levelmap; //store matrixint xSize;};//CLASS Matrix  Definitions:   #include "matrix.h"template <class T>Matrix<T>::Matrix() {levelmap.resize(100,NULL);xSize = 10;}template <class T>Matrix<T>::Matrix(int xDimension, int yDimension) {levelmap.resize((xDimension*yDimension),NULL);xSize = xDimension;}template <class T>Matrix<T>::~Matrix() { }template <class T>void Matrix<T>::in(int x, int y, T data) {//if((xSize*y)+x > levelmap.capacity())levelmap[((xSize * y) + x)] = data;}template <class T>T Matrix<T>::out(int x, int y) {//add bounds checkreturn levelmap.at((xSize * y)+x);}  Usage:   Matrix<int> mapTex; //Construct for holding level detailsMatrix<Sprite> mapSprite; //Construct for holding sprites  (Note: The type "Sprite" is defined elsewhere and works)The problem I have is that it produces the errors:architect.obj : error LNK2001: unresolved external symbol "public: __thiscall Matrix::Matrix(void)" (??0?$Matrix@H@@QAE@XZ)architect.obj : error LNK2001: unresolved external symbol "public: __thiscall Matrix::~Matrix(void)" (??1?$Matrix@H@@QAE@XZ)architect.obj : error LNK2001: unresolved external symbol "public: __thiscall Matrix::Matrix(void)" (??0?$Matrix@VSprite@@@@QAE@XZ)architect.obj : error LNK2001: unresolved external symbol "public: __thiscall Matrix::~Matrix(void)" (??1?$Matrix@VSprite@@@@QAE@XZ)This to me suggested that it couldn't find the ctors/dtor, so I commented out the ctors and dtor and it compiled. I know it's not namespace pollution as I've tried renaming the class and have the same trouble.Any suggestions?[edited by - ShAdOwStRyKeR on February 5, 2004 5:16:46 PM]
  Template member function definitions should be included in the header with the template class declaration. Separate compilation of template functions is in extremely icky state of affairs right now. (Translation: move the stuff from the matrix cpp file into the header and all should be good.)  ;I wonder what the problem could be?Enigma ;  SiCrane got it. Another way is to #include "Matrix.cpp" under your class definition in the header file. Both ways are equally practicle.--Viktor ;  Thanks a lot for the replies. This was the first time I''ve actually needed to use a template class. It''s now working thanks to your help. :-) 