Don't split a template class

Started by
2 comments, last by MaulingMonkey 16 years, 1 month ago
I've learned in some website that it's not advisable to split a template class to .h and .cpp file. Maybe that was an old content. Does this still apply compilers today, say VS2005? If so, how do you create it in one file? How will you include the declaration for that class? Or am I even asking the correct questions?
Advertisement
this : http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12
partly answers your question
The problem is if the source of the member functions are not available when you instantiate the template class then it cannot generate the specialized functions. You can either put it all in the header, make sure the cpp file is available and part of the compilation of the code that uses the class, or force template instantiation for all the specializations you'll need. The easiest way is probably to put all the code in the header.
Still applies.

Most compilers don't implement the export keyword required to avoid this.

The typical solution is to simply put what you'd normally put in a .cpp file into the header, or to rename the file to some other extension and to #include it from said header.

This topic is closed to new replies.

Advertisement