LNK2019 Templates

Started by
3 comments, last by Geometrian 13 years, 3 months ago
Hi,

I have a template function, protoype:
template<typename type_float> void rotate_deg(type_float point[3], type_float vec[3], type_float theta);
Later, in my program, I call:
float v1[3] = {-1.0,0.0,-1.0};float y_axis[3] = {0,1,0};rotate_deg<float>(v1, y_axis, (float)xzangle);
Getting the following error:
error LNK2019:unresolved external symbol "void __cdecl rotate_deg<float>(float * const,float * const,float)" (??$rotate_deg@M@@YAXQAM0M@Z)referenced in function [long function definition]
What is the problem, and how can it be resolved?

Thanks,
-G

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
Long story short template definitions can't be put into source files without either compiler support that practically no compilers come with (the export keyword) or explicit instantiation for each type used in the program. As a result templates are most often simply just defined completely in the headers.
Looks like VS2010 at least supports "export". For portability, I moved all the template functions into the header file, which seems to have fixed it.
Thanks,
G

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Did you actually try using it? If you do MSVC 2010 will spit out:

warning C4237: 'export' keyword is not yet supported, but reserved for future use
I didn't try to implement the code using it (for portability), but typing "export" seemed to be recognized, so I assumed it was usable for the compiler.

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

This topic is closed to new replies.

Advertisement