Posted by Joseph Davidson on March 18, 2001 at 07:46:51:
In Reply to: A little misunderstanding with templates = a big hassle. posted by Matt Green on March 17, 2001 at 20:01:36:
: I started drafting my program today, and began messing around with templates and the Array class. I think I remember noticing in class that the slides had both the declaration and the implementation of classes in the same file and it seemed strange. But I went ahead and split it into the cpp file and the h file, as we've been taught. I kept getting linker errors for every function that was used. I check the syntax of the templated member functions and the class against the notes and Stroustrup's documentation.
: Well 2 hours later I was looking on Deja.com's usenet archives and it seems that you have to consolidate the files, since they perform akin to macros. Hopefully this note will save people some time.
It is not necissary to consolidate files. You can keep the declaration and implementation seperate. You just need to add a
#include "yourcppfile.cpp" at the end of the .h file. Also, you shouldn't include the .h file in the cpp file.
Then just make sure your compiler doesn't try to compile the cpp file.
Post a Followup