Class Templates Again

This is a discussion on Class Templates Again within the C++ Programming forums, part of the General Programming Boards category; Hey Everybody. I have a question. I have a code like this in my .cpp file of the class:
Code:
...

Huh! Once I did as you guys said everything compiles now. Just one thing: I thought that it was always a bad practice to put code in the .h file. Is this an exception, and are there alternatives (ie before I was including a .cpp file). I am not challenging your correctness, just wondering.

>> I thought that it was always a bad practice to put code in the .h file.
It is generally bad practice, but not always. Templates are different, they almost have to be included in the code that calls them so that the compiler can generate code for the type you are using for the template type.

Some people leave the code in a cpp file and then #include that cpp file at the bottom of their header file. If you do that you can make it a .inl file instead of .cpp to indicate that it isn't a normal source file.

I'm adding this as a FYI only because it is widely criticized and not widely implemented by compilers but the export keyword is used to counter that issue. Using either Daved's suggestion or mine is a better alternative, however.

I'm adding this as a FYI only because it is widely criticized and not widely implemented by compilers but the export keyword is used to counter that issue. Using either Daved's suggestion or mine is a better alternative, however.