Avoid Link Errors in VC++ While Using Templates

If you have coded a template class and use it from VC++, you will get a LNK2001 error message on template member functions. This is because Microsoft deviates a bit from C++ specifications. To reproduce the problem, do the following:

1. Declare a template class.

 //HastTable.htemplate l;class HastTable{public:   static float bar;   void foo();}//HastTable.cppint HashTable::bar;  //allocate the static variable in templateclass.template HastTable::foo(){//do something}
2. Try to use HashTable from your main program.
#include

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: