Jump to content
  • Advertisement
Sign in to follow this  
mazelle

Don't split a template class

This topic is 3795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!