I have an assignment in my computer science class where we need to create a templatized version of a C++ class. Our instructor has given us little to no instruction regarding the matter so I've been fumbling through the assignment.
I seem to have made the code from our book work, but I'm not sure the approach I used is appropriate.
Essentially, the example they provide in the book is a "bag" class which is a simple container used to store any manner of standard data types (int, char, string, etc.). The templatized version of this class is declared in a header file called bag5.h and the implementation is given in a .template file called bag5.template. The header then retrieves the code from the .template file using this line, which is near the very end of the header:
The usual way to do this is to put the code for the template directly in the header.
If you really want to keep the code separate from the declarations, you can choose two different extensions that VC++ recognizes as headers, and have the one include the other. For example, have
bag5.h, which includes
As long as both extensions are recognized by VC++ as headers, life is pretty good--you don't have to do much to tell it how to work with them, and it'll automatically apply color coding to both.