News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Definition/implementation file for templates

Started by davereid20, January 19, 2006, 06:31:58 AM

Previous topic - Next topic

davereid20

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?

280Z28

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.
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
Check out The Sam Zone :cool:

Ceniza

Since g++ hasn't support for exported templates I just put all the code in the header file.

Michael

Quote from: 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.

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

Michael
[url="http://img207.imageshack.us/img207/9728/411948picture4em.png"]http://img207.imageshack.us/img207/9728/411948picture4em.png[/url]