tommym121
asked on
Calling template function, I get an error
I got this error;
LNK2019: unresolved external symbol "class std::basic_string<char,str uct std::char_traits<char>,cla ss std::allocator<char> > __cdecl StrUtils::ToString<int>(in t)" (??$ToString@H@StrUtils@@Y A?AV?$basi c_string@D U?$char_tr aits@D@std @@V?$alloc ator@D@2@@ std@@H@Z) referenced in function "private: void __thiscall CRuntime::CreateXMLMapFile (wchar_t const *)" (?CreateXMLMapFile@CRuntim e@@AAEXPB_ W@Z)
In my definition files
"StrUtils.cpp"
In my calling program,
LNK2019: unresolved external symbol "class std::basic_string<char,str
In my definition files
"StrUtils.cpp"
#include "stdafx.h"
#include <stdlib.h>
#include <assert.h>
#include <sstream> // std::istringstream
namespace StrUtils {
template<typename T> string ToString(T val)
{
static std::ostringstream ostr; //output string stream
ostr.str(std::string());
ostr.clear();
ostr<<val;
return ostr.str();
//string abc;
//return abc;
}
}
"StrUtils.hpp"namespace StrUtils {
template<typename T> string ToString(T val);
}
In my calling program,
#include "StrUtils.h"
...
std::cout <<StrUtils::ToString<int>(123);
Can someone let me know why I get the link error
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK, in that case, have you added 'StrUtils.cpp' to your project?
ASKER
Yes both .h and .c. I actually have another functions in StrUtil.cpp that I toke out so it will not confuse what I try to ask
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
ASKER