Templating Question

Original: http://stackoverflow.com/questions/9457407/template-class-compilation-expected-constructor-destructor-or-type-conversion

My Original Post: http://www.cplusplus.com/forum/beginner/99756/

I was just reading a post about template errors similar to my own, I read the solution to the problem and found it troubling.
Basically someone made a class and templated it.

Bleh.h
1
2
3
4
5
6
7
8
template<class t>
class Bleh{
      public: 
           Bleh();
           ~Bleh();
};

#include "Bleh.cpp" 

Bleh.cpp
1
2
3
4
5
6
template<class t>
Bleh<t>::Bleh(){
}
template<class t>
Bleh<t>::~Bleh(){
}


the solution to his problem was to implement the templated classes in the header file...

This seems pretty hacky. As mentioned by someone in the tread and i was wondering is there a more legit, solution?
Last edited on
No. You must put template classes in the header file.

The reason is that templated functions are not "real" functions, only a template, so the compiler needs to see the entire body when you attempt to use one so it can create an instance of it for you.
Topic archived. No new replies allowed.