Code::Blocks Forums

User forums => Help => Topic started by: davereid20 on January 19, 2006, 06:31:58 am

Title: Definition/implementation file for templates
Post by: davereid20 on January 19, 2006, 06:31:58 am
So...asking everyone out there right now...

How do you implement your files when you use templated classes (say a Queue/Stack ADT) and compile with gcc?  I like the idea of definition and implementation in separate files.  Do you put all the defenitions and implementations in the .h file and don't bother with a .cpp file?  Do you put your definitions in a .h file and the implementation in a .cpp file and include both files?  I can't really find a reliable source with a standard way to use templated classes with recent gcc.  What do more experienced users recommend?
Title: Re: Definition/implementation file for templates
Post by: 280Z28 on January 19, 2006, 06:35:03 am
Template definitions need to be placed in the header or you'll be forced to manually instantiate the template for all the types you will ever use in the template when you compile the implementation file.
Title: Re: Definition/implementation file for templates
Post by: Ceniza on January 19, 2006, 07:33:01 am
Since g++ hasn't support for exported templates I just put all the code in the header file.
Title: Re: Definition/implementation file for templates
Post by: Michael on January 19, 2006, 12:06:06 pm
Since g++ hasn't support for exported templates I just put all the code in the header file.

Yes, that is what I do too. I do not really like it, but better than including a cpp file :).

Michael