Sign in to follow this  
ZergUser

Templates and Visual C++ 6.0

Recommended Posts

ZergUser    122
Is it possible to separate a template class declaration from its definition without getting linker errors? The only way to avoid the linker errors seems to be moving the definitions to the header file. If this is the only way around the issue, I guess I'll have to stay with throwing everything in the header file. Are there any other alternatives? Any help would be appreciated. Thanks.

Share this post


Link to post
Share on other sites
SiCrane    11839
The short answer is no.

Unless your compiler supports the export keyword, and MSVC doesn't, then you can't put the definition of a template in a separate source file without explicit instantiation for specific types. Without explicit instantiation, the complete definition of the template needs to be available at point of instantiation, which means, in effect, that the definition needs to go into the header. (Or an inline file of some sort, etc.)

Share this post


Link to post
Share on other sites
Mike2343    1202
A) Stop using buggy IDE's/Compilers. Microsoft Visual C++ Express Edition is free now in every sense.

B) I place my templated code into .inl files that I include at the bottom of the header file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this