Compiling and Linking with Templates
There is an interesting fact that many compilers when you have separate header and cpp files for your definition of a class (AS IS the proper OOP coding sytle) using templates will not put uninstantiated template definitions (specifically the member function) into object (.OBJ) files. This means the linker will look for them failing and giving a linking error.
Solution 1: Put explicit instantiation declarations for each type you are going to use in your .cpp file.
Solution 2: Put all of your code inside the .h file (not normal proceedure) and then you do not have to instantiate will put code in .obj file.
|
||||||||||
© Lynne Grewe |