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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking Errors Using Template Classes

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am using Visual C++ 6.0. I am trying to write a program that calls a template class in another file. AFAIK, I have the class definitions and member functions written correctly and have the proper included headers. I say this because the code containing the class template compiles correctly. However, when I try to compile an outside program which calls this class template, I get the following error:

TestCode.obj : error LNK2001: unresolved external symbol ...

which then points to the constructors that were called at the beginning of my main() program.

Is this an issue with Visual C++? I can't see the use of using templates if I can't call them from other files. When I remove the template nomenclature and use regular classes, everything compiles fine.

Thanks in advance for any help.
 
I honestly think that is an issue with MSVC++. I just ran into that problem quite recently. There are two workarounds that worked for me. One was to put all the function definitions in the header file (whether inline or after the definition). Another was to include the .cpp file instead of the header file when you wanted to use that class.

#include "blah.cpp"

That is kinda sloppy, but so is MSVC++.
If anyone know of why this bug happens (or if it is even a bug or I am just missing somehting) and if there is a service update to fix it, I would appreciate that.

-Skatanic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top