Hopefully simple 'unresolved external symbol' problem
I have an object that gets a list of 'Messages' (in std::string format) and it has to convert part of the string into either an int or a double. I found code online that appears to do this. The problem is that I'm getting unresolved external symbol errors. I think they have something to do with the fact a function is a template, but I'm not sure.
StringToAnyType() is the function I found, everything else I wrote
The header
Code:
//MessageReceiver.h
//Receives Messages from InternalMessageService
#include<vector>
#include<string>
#include<sstream>
class MessageReceiver
{
protected:
int TranslateIntMessage(std::string sMessage); //returns the int part of the message
double TranslateDoubleMessage(std::string sMessage); //returns the double part of the message
std::string TranslateStringMessage(std::string sMessage);
std::vector<std::string>* MessagesReceived; // DO NOT DELETE pointer points to list on IMS
int NumMessRec;
template <class G>
void StringToAnyType(G& t, std::string inString);
std::string StringParser(std::string sMessage);
};
the cpp file
Code:
#include "MessageReceiver.h"
template <class G>
void StringToAnyType(G& t, std::string inString) //turns the string into ints or doubles
{
std::stringstream ss(inString);
ss >> t;
}
std::string StringParser(std::string sMessage) //returns just the number part of the string
{
int NumSpace = 0;
int iter = 0;
for (iter = 0; iter < sMessage.length(); ++iter)
{
if (NumSpace == 2)
{
break;
}
if (sMessage[iter] == ' ')
{
NumSpace++;
}
}
if (NumSpace != 0)
{
//raise error
return 0;
}
sMessage.erase(0,iter);
return sMessage;
}
int MessageReceiver::TranslateIntMessage(std::string sMessage)
{
sMessage = StringParser(sMessage);
int iReturnInt = 0;
const int& Return = iReturnInt;
StringToAnyType(Return, sMessage);
return iReturnInt;
}
double MessageReceiver::TranslateDoubleMessage(std::string sMessage)
{
sMessage = StringParser(sMessage);
double iReturnDouble = 0;
StringToAnyType(iReturnDouble, sMessage);
return iReturnDouble;
}
std::string TranslateStringMessage(std::string sMessage)
{
sMessage = StringParser(sMessage);
return sMessage;
}
the errors (curse their longness ;) )
Code:
MessageReceiver.obj : error LNK2019: unresolved external symbol "protected: void __thiscall MessageReceiver::StringToAnyType<int const >(int const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??$StringToAnyType@$$CBH@MessageReceiver@@IAEXABHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "protected: int __thiscall MessageReceiver::TranslateIntMessage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?TranslateIntMessage@MessageReceiver@@IAEHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
MessageReceiver.obj : error LNK2019: unresolved external symbol "protected: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall MessageReceiver::StringParser(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?StringParser@MessageReceiver@@IAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V23@@Z) referenced in function "protected: int __thiscall MessageReceiver::TranslateIntMessage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?TranslateIntMessage@MessageReceiver@@IAEHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
MessageReceiver.obj : error LNK2019: unresolved external symbol "protected: void __thiscall MessageReceiver::StringToAnyType<double>(double &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??$StringToAnyType@N@MessageReceiver@@IAEXAANV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "protected: double __thiscall MessageReceiver::TranslateDoubleMessage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?TranslateDoubleMessage@MessageReceiver@@IAENV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
I'm sure it's something simple, but it doesn't appear to be anything I've run into before