Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

template classes

Status
Not open for further replies.

beginner76

Programmer
Jun 21, 2005
1
US
When I create a template class, should I place all definitions for the template member functions in the same file (~code segment)? (Deitel seems to imply this in their C++ book, Chapter on templates).

I get link errors if I do not do that (I use MS Visual Studio)... If such is indeed required, then this really limits how much code I can stick inside a template while being organized... I am confused...
 
Yes this is correct. There is a feature in the standard (the export keyword) that is supposed to help this so that you can separate the implementation, but at most only a single compiler actually supports it (not VC++) and even then I don't think they support it all that well. I believe they are trying to make this easier in the next standard, but until then you just have to put all your template code in the header file, or you can include the implementation file at the bottom of your header so that the definitions are included.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top