- #1
- 6,982
- 299
This little test of templates and non-member functions works fine:
I want to split this up so function mytest is in its own .cpp file, but I can't get it to work.
It compiles OK but I get
which suggests it doesn't realize it has to instantiate the templates.
What am I doing wrong? FWIW changing "class T" to "typename T" makes no difference.
Code:
// test5.cpp : main project file.
#include "stdafx.h"
using namespace System;
template <class T> void mytest(void);
int main(array<System::String ^> ^args)
{
mytest<double>();
mytest<int>();
Console::ReadLine();
return 0;
}
template <class T> void mytest (void)
{
T x = 1;
T y = 2;
Console::WriteLine("size of T = {0} x/y = {1}",sizeof(T),x/y);
}
I want to split this up so function mytest is in its own .cpp file, but I can't get it to work.
It compiles OK but I get
Code:
test5.obj : error LNK2028: unresolved token (0A000006) "void __cdecl mytest<int>(void)" (??$mytest@H@@$$FYAXXZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
test5.obj : error LNK2028: unresolved token (0A000007) "void __cdecl mytest<double>(void)" (??$mytest@N@@$$FYAXXZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
test5.obj : error LNK2019: unresolved external symbol "void __cdecl mytest<int>(void)" (??$mytest@H@@$$FYAXXZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
test5.obj : error LNK2019: unresolved external symbol "void __cdecl mytest<double>(void)" (??$mytest@N@@$$FYAXXZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
What am I doing wrong? FWIW changing "class T" to "typename T" makes no difference.