Author Topic: Definition/implementation file for templates  (Read 3842 times)

davereid20

  • Guest
Definition/implementation file for templates
« 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?

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: Definition/implementation file for templates
« Reply #1 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.
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Definition/implementation file for templates
« Reply #2 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.

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Definition/implementation file for templates
« Reply #3 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