Implementing Constructor of Generic Class

Hi, I'm trying to implement the code for the constructor of the following class, outside it:

1
2
3
4
5
6
7
8
9
10
template <class T> 
class Matrix {
   	
	int w, h;
	T* m;

  public:
	Matrix (int _w, int _h);
    int get_width ();
};

As,

1
2
3
4
5
template <class T>
Matrix<T>::Matrix (int _w, int _h){
	w = _w;
	h = _h;
}


But it won't work! Anyone knows how to solve this problem? (I'm using VS08)


Thanks!
I had a similar problem earlier that got resolved. Are you splitting your code into header and source? If so, you should put everything in a header file; it's one of those silly things that C++ does.

Also, welcome to the forums :)
I believe you cannot split template functions up, they need to be included in the .cpp of every file that you want to use them in, because they are not normal functions. I would assume the same applies to a template class, (put it in all the .hpps) but I haven't checked.
Indeed, I was declaring the class at a header file and trying to implement it on a source one. Putting everything together in the header file works fine! Thank you!

Well, I'll try to find a formal explanation about this behaviour ;P

Topic archived. No new replies allowed.